目前文档我还没写,先拿AI生成的用着吧
我感觉我写模组已经写的神志不清了🤮
以下是AI替我写的文档
The music_player peripheral provides control over NetMusic music players, allowing you to play, manage, and interact with music CDs and online music streams.
Starts playing the current CD in the music player.
Example:
local player = peripheral.find("music_player")
player.play()Stops the currently playing music.
Example:
player.stop()Checks if the music player is currently playing.
Returns:
boolean-trueif playing,falseotherwise
Example:
if player.isPlaying() then
print("Music is currently playing")
endChecks if there is a CD in the music player.
Returns:
boolean-trueif a CD is present,falseotherwise
Example:
if player.hasCD() then
print("CD loaded")
endTakes a CD from another container and places it in the music player.
Parameters:
from(string) - Direction of the container (e.g., "front", "back", "left", "right")slot(number) - Slot number in the container (Lua indexing starts at 1)
Throws:
- If computer is not connected
- If container not found
- If target is not a container
- If slot index is out of range
- If item is not a valid music CD
- If music player already contains an item
Example:
player.pushCD("right", 1) -- Take CD from right container, slot 1Removes the CD from the music player and places it in another container.
Parameters:
to(string) - Direction of the target containerslot(number) - Slot number in the target container
Throws:
- If computer is not connected
- If container not found
- If target is not a container
- If slot index is out of range
- If music player is empty
- If cannot place item in target slot
- If target slot is full
- If target slot contains different items
Example:
player.pullCD("left", 3) -- Place CD in left container, slot 3Gets the URL of the current CD.
Returns:
string- The song URL, ornilif no valid CD
Example:
local url = player.getUrl()
if url then
print("Playing from: " .. url)
endGets the name of the current song.
Returns:
string- The song name, ornilif no valid CD
Example:
local name = player.getName()
print("Now playing: " .. (name or "Unknown"))Gets the translated name of the current song.
Returns:
string- The translated song name, ornilif no valid CD
Gets the duration of the current song in seconds.
Returns:
number- Song duration in seconds, or 0 if no valid CD
Example:
local duration = player.getSecond()
print("Song duration: " .. duration .. " seconds")Gets the list of artists for the current song.
Returns:
table- Array of artist names, or empty table if no valid CD
Example:
local artists = player.getArtists()
for i, artist in ipairs(artists) do
print("Artist " .. i .. ": " .. artist)
endChecks if the current song requires VIP access.
Returns:
boolean-trueif VIP song,falseotherwise
Checks if the current CD is read-only.
Returns:
boolean-trueif read-only,falseotherwise
Gets the current playback position in seconds.
Returns:
number- Current playback time in seconds
Example:
local currentTime = player.getCurrentTime()
local totalTime = player.getSecond()
print(string.format("Progress: %.1f / %.1f seconds", currentTime, totalTime))Writes new song data to the current CD.
Parameters:
url(string) - The song URLsecond(number) - Song duration in secondssongName(string, optional) - Custom song name (default: "电脑刻录唱片")
Throws:
- If music player is empty
- If CD is read-only
Example:
player.setCDUrl("https://example.com/song.mp3", 180, "My Custom Song")Converts a NetEase Music ID to a playable URL.
Parameters:
id(number) - NetEase Music song ID
Returns:
string- Playable URL
Example:
local url = player.idToUrl(123456)
player.setCDUrl(url, 240, "Converted Song")Extracts NetEase Music ID from a URL.
Parameters:
url(string) - NetEase Music URL
Returns:
number- Song ID, ornilif invalid URL
Example:
local id = player.urlToId("https://music.163.com/song/media/outer/url?id=123456.mp3")
print("Song ID: " .. (id or "Unknown"))Note: These functions require the NetMusicList mod to be installed.
Sets the current playlist index.
Parameters:
index(number) - Playlist index (Lua indexing starts at 1)
Throws:
- If NetMusicList mod not installed
- If music player is empty
- If item is not a playlist
Example:
player.setListIndex(5) -- Play the 5th song in the playlistGets the current playlist index.
Returns:
number- Current playlist index (1-based)
Throws:
- If NetMusicList mod not installed
- If music player is empty
- If item is not a playlist
Example:
local currentIndex = player.getListIndex()
print("Currently playing track: " .. currentIndex)Gets the total number of songs in the playlist.
Returns:
number- Total playlist count
Throws:
- If NetMusicList mod not installed
- If music player is empty
Example:
local totalTracks = player.getListCount()
print("Playlist contains " .. totalTracks .. " tracks")Sets the playlist playback mode.
Parameters:
mode(string) - Playback mode (e.g., "sequential", "random", "repeat")
Throws:
- If NetMusicList mod not installed
- If music player is empty
Example:
player.setPlayMode("random") -- Enable random playbackAlways wrap peripheral calls in error handling:
local player = peripheral.find("music_player")
if player then
local success, err = pcall(function()
player.play()
end)
if not success then
print("Error: " .. err)
end
else
print("No music player found")
end-- Simple music player controller
local player = peripheral.find("music_player")
if player and player.hasCD() then
print("Now playing: " .. (player.getName() or "Unknown"))
print("Duration: " .. player.getSecond() .. " seconds")
if not player.isPlaying() then
player.play()
end
-- Monitor playback
while player.isPlaying() do
local current = player.getCurrentTime()
local total = player.getSecond()
local progress = math.floor((current / total) * 100)
print(string.format("Progress: %d%%", progress))
sleep(5)
end
else
print("No CD loaded or player not found")
end