iTunes.play()

Type function
Library PLUGIN_NAME.*
Return value [TYPE][api.type.TYPE]
Revision 2014.2419
Keywords
Sample code
See also

Overview

Plays an item selected from the iTunes library.

Syntax

iTunes.play( songUrl )
iTunes.play( songUrl, onComplete )
songUrl (required)

String. The song url you wish to play, this url is retrieved via the media.show callback function.

onComplete (optional)

Listener. The callback function that is executed after dismissing the iTunes library picker.

Examples

-- Require the iTunes library
local iTunes = require( "CoronaProvider.plugin.iTunes" )
local widget = require( "widget" )

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


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


-- Function that gets executed after media item(s) have been chosen
local function onMediaChosen( event )
    -- If a song was picked, print it's details
    if event.data then
        for i = 1, #event.data do
            print( "url", event.data[i].url )
            print( "album artist", event.data[i].albumArtist )
            print( "album title", event.data[i].albumTitle )
            print( "song title", event.data[i].songTitle )
            print( "performing artist", event.data[i].performingArtist )
            print( "composer", event.data[i].composer )
            print( "genre", event.data[i].genre )
            print( "lyrics", event.data[i].lyrics )
            print( "podcast title", event.data[i].podcastTitle )

            -- Copy the song table from event.data
            mediaItems[i] = event.data[i]
        end

        -- Play the first item chosen
        iTunes.play( mediaItems[1].url, onPlaybackEnded )
    end 
end


-- Function to show the iTunes picker
local function showItunesLibrary()
    -- Options to pass to iTunes.show
    local options =
    {
        allowsPickingMultipleItems = true,
        promptTitle = "Select some songs!",
    }

    -- Show the users iTunes library
    iTunes.show( options, onMediaChosen )
end


-- Button to show the picker
local showPicker = widget.newButton
{
    label = "Show Picker",
    onRelease = showItunesLibrary,
}
showPicker.x = display.contentCenterX
showPicker.y = stopButton.y + ( showPicker.contentHeight + 45 )