iTunes.isPlaying()

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

Overview

Returns a boolean indicating if an item chosen from the iTunes media library is currently playing.

Syntax

iTunes.isPlaying()

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

        print( "is playing?", iTunes.isPlaying() )

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

        print( "is playing?", iTunes.isPlaying() )
    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 )