Player Component


Properties

isPlaying
  Reports whether the media is playing.
Data type: boolean
Designer Writable false
Code Writeable false
Code Readable true let variable = playerName.isPlaying

loop
  If true, the Player will loop when it plays. Setting Loop while the player is playing will affect the current playing.
Data type: boolean
Designer Writable true <player name="playerName" loop="true">
Code Writeable true playerName.loop = true
Code Readable true let variable = playerName.loop

playOnlyInForeground
  If true, the Player will pause playing when leaving the current screen; if false (default option), the Player continues playing whenever the current screen is displaying or not.
Data type: boolean
Designer Writable true <player name="playerName" playOnlyInForeground="true">
Code Writeable true playerName.playOnlyInForeground = true
Code Readable true let variable = playerName.playOnlyInForeground

source
  Sets the audio source.
Data type: string
Designer Writable true <player name="playerName" source="/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/My Documents/Recordings/app_inventor_1675592812960.3gp">
Code Writeable true playerName.source = "/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/My Documents/Recordings/app_inventor_1675592812960.3gp"
Code Readable true let variable = playerName.source

volume
  Sets the volume property to a number between 0 and 100.
Data type: number
Designer Writable true <player name="playerName" volume="100">
Code Writeable true playerName.volume = 100
Code Readable false

class
  The styling class of the the component
Data type: string
Designer Writable true <player name="playerName" class="Test class">
Code Writeable false
Code Readable false

id
  The styling id of the the component
Data type: string
Designer Writable true <player name="playerName" id="Test id">
Code Writeable false
Code Readable false

name
  The name of the component that will be used to refer to it in code.
Data type: string
Designer Writable true <player name="playerName" name="testComponent">
Code Writeable false
Code Readable false

Methods

Method name Description Parameters
pause Suspends playing the media if it is playing.
playerName.pause()
start Plays the media. If it was previously paused, the playing is resumed. If it was previously stopped, it starts from the beginning.
playerName.start()
stop Stops playing the media and seeks to the beginning of the song.
playerName.stop()
vibrate Vibrates for specified number of milliseconds.
playerName.vibrate(milliseconds)
playerName.vibrate(1000)
milliseconds number
addEventListener Method used to create event listeners.
See Events below for samples.
eventName string
eventCallbackFunction callback

Events

Event name Description Parameters
completed Indicates that the media has reached the end
playerName.addEventListener(
    "completed",
    function () {
        //Your code here
    }
)
otherPlayerStarted This event is signaled when another player has started (and the current player is playing or paused, but not stopped).
playerName.addEventListener(
    "otherPlayerStarted",
    function () {
        //Your code here
    }
)