iTunes.play()

类型 函数
返回值
修订版 发行版 2024.3703
关键字 play,iTunes
另请参阅 iTunes
iTunes.pause()
iTunes.resume()
iTunes.stop()

概述

播放从 iTunes 库中选择的项目。

语法

iTunes.play( songUrl )
iTunes.play( songUrl, onComplete )
songUrl (必需)

字符串. 要播放的音乐 URL,从 iTunes.show() 的回调函数中检索。

onComplete (可选)

侦听器. 在退出 iTunes 库选择器后执行的回调函数。

示例

local iTunes = require( "plugin.iTunes" )

-- Table to store media items
local mediaItems = {}

-- Function that is executed when song playback is complete
local function onPlaybackEnded()
    print( "Playback completed!" )
end

-- Function that is executed after media item(s) have been chosen
local function onMediaChosen( event )

    if ( event.data ) then
        for i=1,#event.data do
            mediaItems[i] = event.data[i]
        end
        
        --play the first item chosen
        iTunes.play( mediaItems[1].url, onPlaybackEnded )

    end 
end

local iTunesOptions =
{
    allowsPickingMultipleItems = true,
    promptTitle = "Select some songs"
}
iTunes.show( iTunesOptions, onMediaChosen )