CubiPlayer is MineOS library that provides non-blocking playing queue for OpenFM radio and convenient interface to interract with it.
Type | Parameter | Description |
---|---|---|
component | radio | OpenFM radio component from Component library |
Type | Parameter | Description |
---|---|---|
string | name | Name of the track |
string | url | Direct url to audio stream/file that OpenFM supports |
int | duration | Duration of the track in seconds |
local track = {
["name"] = "Whales & ggnoaa - Paranoia",
["url"] = "https://api-2.datmusic.xyz/dl/d831d992/bf3e8e7c",
["duration"] = 185
}
Type | Parameter | Description |
---|---|---|
table | track | Track object to add in queue |
Type | Parameter | Description |
---|---|---|
int | index | Track index in queue to delete |
Type | Parameter | Description |
---|---|---|
int | volume | Value of volume to set on OpenFM radio |
local GUI = require("GUI")
local component = require("Component")
local cp = require("CubiPlayer")
-- Check if radio connected
if not component.isAvailable("openfm_radio") then
GUI.alert("This program requires an OpenFM Radio")
return
end
-- Create new player instance
local player = cp.player(component.openfm_radio)
-- Set callback function on event that calls when player stops
player.onEnd = function()
GUI.alert("Playing queue is over!")
return
end
-- Create track objects
local track1 = {
["name"] = "Whales & ggnoaa - Paranoia",
["url"] = "https://api-2.datmusic.xyz/dl/d831d992/bf3e8e7c",
["duration"] = 185
}
local track2 = {
["name"] = "Kobaryo - Galaxy Friends",
["url"] = "https://api-2.datmusic.xyz/dl/bd9b3ea5/c4730495",
["duration"] = 240
}
-- Add tracks to playing queue
player:addTrack(track1)
player:addTrack(track2)
-- Start playback
player:play()