Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Rookai
Binge Watcher

Accessing local (tmp:/) audio files to be played by roAudioplayer

Hi,

I have a local mp3 audio file stored in tmp:/ ("tmp:/audio.mp3), and this file is generated from response of an API call " AsyncPostFromFileToFile " . I would like to play it using roAudioPlayer component. When I pass it to roAudioPlayer, it does not play anything; where it plays from an external URL perfectly. This is my script:

' Create the roAudioPlayer object
        wavFilePath = "tmp:/audio.mp3"
        audioPlayer = CreateObject("roAudioPlayer")
        port = CreateObject("roMessagePort")
        audioPlayer.SetMessagePort(port)

        ' Create the associative array for the audio content
        song = CreateObject("roAssociativeArray")
        song.url = wavFilePath
        file = CreateObject("roFileSystem")
        print file.GetVolumeList() 
        print file.GetDirectoryListing("tmp:/") 'tmp:/audio.mp3 exists
        ' Add content to the audio player and start playback
        audioPlayer.addcontent(song)
                ' urlPath = "file://" + wavFilePath
                ' print "urlPath: "; urlPath
        'urlPath = "http://www.sdktestinglab.com/Tutorial/sounds/audionode.mp3"                
        'audioPlayer.setcontentlist([{ url: urlPath }]) ' works when tried individually
        'audioPlayer.addcontent(song)
        audioPlayer.setloop(false)
        audioPlayer.play()

        print "Audio playback triggered for file: " + wavFilePath

        ' Event loop to handle audio player events
        while true
            msg = wait(0, port)
            if type(msg) = "roAudioPlayerEvent"
                if msg.isStatusMessage()
                    print "roAudioPlayerEvent: "; msg.getmessage(); msg.getindex()
                    if msg.getmessage() = "end of playlist"
                        exit while
                    end if
                end if
            end if
        end while

 

This is the consul log for this section (please note I require msg.getindex() for each message to monitor progress; for URL-based mp3 file, it goes 0 to 1000):

roAudioPlayerEvent: prebuffer started 0
roAudioPlayerEvent: startup progress 0
roAudioPlayerEvent: startup progress 66
roAudioPlayerEvent: startup progress 132
roAudioPlayerEvent: startup progress 198
roAudioPlayerEvent: startup progress 264
roAudioPlayerEvent: startup progress 330
roAudioPlayerEvent: prebuffer done 0
roAudioPlayerEvent: startup progress 330
roAudioPlayerEvent: prebuffer done 0
roAudioPlayerEvent: startup progress 330
roAudioPlayerEvent: Content contains no playable tracks. 0
roAudioPlayerEvent: end of playlist 0

 

Answers like following suggest the local path can be fed to roURLTransfer by using prefix "file://", but I had no luck trying it:

https://community.roku.com/t5/Roku-Developer-Program/Simple-Quesiton-on-URLs/m-p/301815/highlight/tr...

What am I doing wrong? What should I change to make this work? Any help will be appreciated.

0 Kudos
5 REPLIES 5
renojim
Community Streaming Expert

Re: Accessing local (tmp:/) audio files to be played by roAudioplayer

I don't see anything that's obviously wrong in your code and I just tried playing an MP3 from tmp:/ and didn't have a problem.  I suspect your MP3 isn't being properly saved to tmp:/.  AsyncPostFromFileToFile?  Is that what you're using that to save the MP3?  I can't say I've ever used it, but check the file that gets saved to tmp:/ with something like roFileSystem stat and/or read it into an roByteArray to check its contents.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
Rookai
Binge Watcher

Re: Accessing local (tmp:/) audio files to be played by roAudioplayer

Thanks a lot for your response. I followed your instructions and it seems the file is being created, but only the first 4 characters of the response is being stored in the file. If I understand correctly,

msg.GetResponseCode()

returns 200 as soon as the response starts coming in, and it does not wait for the API to return the complete response if the process is not instantaneous. What would be the proper way to make it wait until the response return is complete? I tried a few tweaks but each of them generates new complexities.

 

0 Kudos
renojim
Community Streaming Expert

Re: Accessing local (tmp:/) audio files to be played by roAudioplayer

I don't know what to suggest on the Roku side, but I usually use something like curl to test interfacing to a server.  Something like:

curl --data-raw @command.txt -o apiresponse.out http://apiurl.com/api

That should mimic what AsyncPostFromFileToFile does.

I tried it myself both using curl and on my Roku device connecting to my own server and both worked as expected.

I assume you're using msg = wait(0,port) to wait for the response.  It shouldn't be returning until the transfer is complete.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
Rookai
Binge Watcher

Re: Accessing local (tmp:/) audio files to be played by roAudioplayer

Hi @renojim 

Thanks a lot for your help. It seems the roURLTransfer works on back of curl. I tested my server with both curl and postman, and they both worked fine and waited until the end of the file was detected (0.7 second to 5 seconds). However, when I run it using AsyncPostFromFileToFile or any other variation of AsyncPost, the port returns immediately and does not wait at all until the response is fully received. Is there anything else you can think of?

Perhaps @RokuKevin or @RokuAustin could kindly chime in?

 

 

 

 

 

0 Kudos
renojim
Community Streaming Expert

Re: Accessing local (tmp:/) audio files to be played by roAudioplayer

My only other thought is packet sniffing and Wireshark, but that can be a pain.  I don't know what could be causing it to return immediately.  I don't see that in my test, but my test is pretty trivial and everything is local.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.