Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NBPlayer
- -- by MysticT
- -- load the nb api
- if not nb then
- os.loadAPI("nb")
- if not nb then
- print("Couldn't load nb api. Check if you installed it correctly.")
- return
- end
- end
- -- detect a modem and connect
- local function connect()
- for _,s in ipairs(rs.getSides()) do
- if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
- rednet.open(s)
- return true
- end
- end
- return false
- end
- -- try to connect to rednet
- if not connect() then
- print("No modem found")
- return
- end
- -- play a song file
- local function playFile(sPath)
- local file = fs.open(sPath, "r")
- if file then
- local s = file.readAll()
- file.close()
- local tSong = textutils.unserialize(s)
- if tSong and type(tSong) == "table" then
- local title = tSong.name
- if not title or title == "" then
- title = "Untitled"
- end
- local author = tSong.author
- if not author or author == "" then
- author = "Unknown"
- end
- print("Playing: ", title, " - by ", author)
- if tSong.original_author and tSong.original_author ~= "" then
- print("Original Author: ", tSong.original_author)
- end
- if tSong.lenght then
- print("Lenght: ", tSong.lenght)
- end
- nb.playSong(tSong)
- return true
- end
- return false, "Unknown file format."
- end
- return false, "Error opening file "..sPath
- end
- -- Start Program
- -- get arguments
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print("Usage: nbplay <file>")
- return
- end
- -- load and play the file
- local ok, err = playFile(tArgs[1])
- if not ok then
- return false, err
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement