Tested on Roku 2 HD using firmware v4.1
BUGS in v3 SDKFeatures that would greatly improve audio support
- Add SetPositionNotificationPeriod() to ifAudioPlayer interface
- Add isPlaybackPosition() event type to roAudioPlayerEvent
- Use PlayStart Meta-Data attribute to resume audio playback from a specific position
- Use SDPosterUrl and HDPosterUrl meta-data attributes to set a background image on roVideoScreens
- Add SetBGDisplayMode() method to roVideoScreen to determine whether background image should be full screen or scale-to-fit
Resuming playback for audio filesI've only tested these issues using mp3 files. The main stream that I use for testing is hosted on
archive.org. I initially tried to implement an audio player that provided a save/resume feature using a springboard screen and roAudioPlayer. Unfortunately since there isn't a playback notification event there was no way to retrieve the current position. The only way I was able to determine the audio playback position was to use a roTimespan object in combination with the wait() function. The code below is a much abbreviated example of how this worked.
currentpos = 0
totalLength = 3600
isPlaying = false
timer = CreateObject("roTimespan")
while true
msg = wait(1000, port)
if type(msg) = "roAudioPlayerEvent" then
if msg.isStatusMessage() then
message = msg.getMessage()
if message = "start of play" then
timer.Mark() 'start the timer
isPlaying = true
endif
elseif msg.isPaused()
currentpos = currentpos + timer.TotalSeconds()
isPlaying = false
elseif msg.isResumed()
timer.Mark() 'restart the timer
isPlaying = true
endif
elseif isPlaying then
springboard.SetProgressIndicator(currentpos + timer.TotalSeconds(), totalLength)
endif
end while
I was able to keep track of the current playback position and update the progress indicator on the springboard screen but there was no way to resume playback at a specific position. Calling Pause() and then Resume() work just fine, but if the playback position is saved to the registry and you want to return to that position at a later time then there was simply no way to accomplish it. The PlayStart and StreamStartTimeOffset meta-data attributes have no effect on a mp3 file (possibly all audio files but I haven't tested wma). Calling the Seek() method on a roAudioPlayer prior to or after calling Play() had no effect. As far as I know it is literally impossible to resume playback at a specific position using roAudioPlayer.
My last option was to switch to a roVideoScreen just to play mp3 files. Unfortunately I discovered some of the same issues with roVideoScreen. While it did provide the playback position notification and eliminated the need to use roTimespan/wait I still couldn't resume at a specific position. Calling Seek() prior to or after calling Show() had no effect, calling Seek() from the isStreamStarted() notification had no effect, and the PlayStart and StreamStartTimeOffset meta-data attributes were ignored for mp3 files. The ONLY way I was able to resume playback at a specific position was with the code below.
resume = 100
currentpos = 0
isResumed = false
while true
msg = wait(0, port)
if type(msg) = "roVideoScreenEvent" then
if msg.isPlaybackPosition() then
currentpos = msg.GetIndex()
print "playback position: "; currentpos
if not isResumed and resume > 0 then
isResumed = true
player.Seek((resume + 1) * 1000)
endif
endif
endif
end while
It really shouldn't be that difficult to save/resume an audio playback position. Since it CAN be accomplished using roVideoScreen I think it would be incredibly useful to have the option to set a default background image on that screen. If a roVideoScreen is being used to play an audio file then it will only display a black background along with the progress bar. I know I could use roImageCanvas to display an image on top of the roVideoScreen but I would then lose the user controls (play, pause, etc). Please add the option to use the SDPosterUrl and HDPosterUrl meta-data to display a background image on roVideoScreens. I think a new method should also be added to control the scaling/aspect ratio for the bg image (e.g., SetBGDisplayMode("scale-to-fit").