Page 1 of 1

get duration of audio on iOS player

Posted: Sun Apr 20, 2014 4:22 am
by Coffee1633
Hi

I can find duration and use what I need on the desktop with

Code: Select all

put the duration of player "sentence" / the timeScale of player "sentence" into tSentenceDuration
and the dictionary says that duration can be used with iOS platforms but I can't get it too work

dictionary example
put (the duration of me/the timeScale of me) into totalSeconds

the problem is how can I indicate the iOS mobile player?

Up until now I only use commands like mobilePlaySoundOnChannel, or mobilePausePlayingOnChannel etc

but those command require the file name, channel, type and such. Is there a relation between the channel name and the player name? I spent several hours on this one thing and have come to a deadend. Any one know?

regards,
bob coffee

Re: get duration of audio on iOS player

Posted: Sun Apr 20, 2014 5:33 am
by Jellicle
As far as I know the player object isn't available on iOS. You can use channels or the iOS native player instead, but the native player is the only one that gives you access to the duration of an audio file. It has lots of other properties you can set and get (the documentation mentions movies but it works for audio files too):

• filename - returns the filename or URL of the media set on the player, if any.
• showController - returns true if the controller is displayed over the content.
• currentTime - returns the current position of the playhead, measured in milliseconds (maps to the native currentPlaybackTime property). This is an integer value.
• looping - returns true if the playback of the movie loops indefinitely.
• fullscreen (iOS Only) - returns true if the player's content is set to play fullscreen.
• preserveAspect (iOS Only) - returns true if the player's content should preserve its aspect ratio when scaled to fit within the control's bounds.
• useApplicationAudioSession (iOS Only) - returns true if the movie uses a system-supplied audio session or not (maps to the native useApplicationAudioSession property).
• shouldAutoplay (iOS Only) - returns true if the playback of network-based content begins automatically when there is enough buffered data to ensure uninterrupted playback (maps to the native shouldAutoplay property).
• allowsAirPlay (iOS Only) - returns true if a control is presented to allow the user to choose AirPlay-enabled hardware for playback (maps to the native allowsAirPlay property). Note: This property is only supported on iOS 4.3 and later.
duration (iOS Only) - returns the duration of a movie, measured in milliseconds (maps to the native duration property). This is an integer value.
• playableDuration (iOS Only) - returns the amount of currently playable content, measured in milliseconds (maps to the native playableDuration property). This is an integer value.
• startTime (iOS Only) - returns the position at which playback starts, measured in milliseconds (maps to the native initialPlaybackTime property). This is an integer value.
• endTime (iOS Only) - returns the position at which playback ends, measured in milliseconds (maps to the native endPlaybackTime property). This is an integer value.
• playRate (iOS Only) - returns the current playback rate for the player (maps to the native currentPlaybackRate property). This represents a multiplier for the default playback rate of the current content. A value of 0.0 indicates playback is stopped, while a value of 1.0 indicates normal speed. Positive values indicate forward playback, while negative values indicate reverse playback. This is real value.
• loadState (iOS Only) - returns the network load state of the player (maps to the native loadStateproperty). This is a comma delimited list of zero or more of the following:
◦ playable - enough data is available to start playing, but it may run out before playback finishes.
◦ playthrough - enough data has been buffered for playback to continue uninterrupted.
◦ stalled - buffer of data has stalled and playback may pause automatically if the player runs out of data.
• playbackState (iOS Only) - returns the current playback state of the player (maps to the native playbackState property). This is one of the following:
◦ stopped - playback is stopped and commences from the beginning when started.
◦ playing - playback is current underway.
◦ paused - playback is paused and resumes from the point it was paused.
◦ interrupted - playback is temporarily interrupted, perhaps because the buffer ran out of content.
◦ seeking forward - the player is currently seeking towards the end of the movie.
◦ seeking backward - the player is currently seeking towards the beginning of the movie.
• naturalSize (iOS Only) - The raw size of a video frame in pixels (maps to the native naturalSize property). This is a comma-separated list of two integers, the first is the width, the second is the height.

Hope that helps.

Gerry

Re: get duration of audio on iOS player

Posted: Sun Apr 20, 2014 5:59 am
by Coffee1633
thanks Gerry

That is a start but I am getting stuck with the actual line of code. Does anyone know what the line of code would be to get the duration of an audio file on iOS? I just can't get it too work and debugging iOS is a nightmare

bob

Re: get duration of audio on iOS player

Posted: Sun Apr 20, 2014 9:01 am
by Jellicle
Stick this code in the card script:

Code: Select all

local playerID

on makeplayer
    mobileControlCreate "player", "playerControl"
    -- the second param is the name you give the object - can be anything
    put the result into playerID 
    mobileControlSet  playerID, "useApplicationAudioSession", "true" 
    mobileControlSet playerID, "fullscreen", false
    mobileControlSet playerID, "preserveAspect", true
    mobileControlSet playerID, "showController", true
    mobileControlSet playerID, "rect", "0,100,640,300"  
    mobileControlSet playerID, "visible", true
   mobileControlSet playerID, "filename", (specialfolderpath ("Documents") & "/mp3/soundfile.mp3")
  -- the previous line assumes there is an mp3 file named 
  -- "soundfile.mp3" on the device in Documents/mp3/
  answer mobileControlGet (playerID,"duration")
end makeplayer
Run the app in the simulator (making sure the soundfile.mp3 file is copied to right place either manually or via code) and then call makeplayer from a button script.

Let us know how you go :)

Gerry

Re: get duration of audio on iOS player

Posted: Sun Apr 20, 2014 9:22 am
by Coffee1633
Thanks Gerry

I see the line I need.

mobileControlGet (playerID,"duration")

and of course all the other supporting code to make that line work. I will try it tonight in my app.
thanks a bunch for your quick help.

cheers,
coffee16