androidaudiorhomobile

Mp3/Wav Playback in Rhomobile 5.4 on Android


I have an app that attempts to play a small sound file using the following code:

Alert.play_file("/public/audio/" + $audio_file + ".mp3", "audio/x-mp3") if Configuration.current.audio_prompt?

When I use this code the app throws a "Server Error" that looks like this:

enter image description here

I have tried using the Media player API instead of the Alert API, and received essentially the same error.

Is this a codec issue?

For Wav files (yes the wav file is correctly pointed to instead of mp3 in those lines) the error is not thrown, but the sound itself does not play.

EDIT

I was finally able to get some logcat data during this error, and received this:

09-25 19:51:03.122 8891 8948 I APP : I 09/25/2016 19:51:03:122 000022f4 HttpServer| GC End. 09-25 19:51:03.123 8891 8948 I APP : I 09/25/2016 19:51:03:123 000022f4 HttpServer| Process URI: '/app/Animation/draw' 09-25 19:51:03.124 8891 8948 I APP : I 09/25/2016 19:51:03:124 000022f4 APP| RHO serve: /app/Animation/draw 09-25 19:51:03.125 8891 8948 I APP : I 09/25/2016 19:51:03:124 000022f4 APP| Params: {"char_id"=>"6", "ajax"=>"", "run"=>"1"} 09-25 19:51:03.131 500 500 V AudioFlinger: releasing 55 from 8891 for -1 09-25 19:51:03.131 500 500 V AudioFlinger: decremented refcount to 0 09-25 19:51:03.131 500 500 V AudioFlinger: purging stale effects 09-25 19:51:03.132 8891 8948 E ExtMediaPlayer-JNI: QCMediaPlayer could not be located.... 09-25 19:51:03.132 8891 8948 D MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0 09-25 19:51:03.132 8891 8948 E ExtMediaPlayer-JNI: QCMediaPlayer could not be located.... 09-25 19:51:03.132 8891 8948 D MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0 09-25 19:51:03.132 500 4043 V AudioFlinger: acquiring 56 from 8891, for -1 09-25 19:51:03.132 500 4043 V AudioFlinger: added new entry for 56 09-25 19:51:03.133 8891 8948 I APP : E 09/25/2016 19:51:03:133 000022f4 RhoFileApi| Can not open file descriptor: /public/audio/xing4.mp3: open failed: ENOENT (No such file or directory) 09-25 19:51:03.133 8891 8948 I APP : E 09/25/2016 19:51:03:133 000022f4 NotificationSingleton| null 09-25 19:51:03.133 8891 8948 I APP : java.lang.IllegalArgumentException 09-25 19:51:03.133 8891 8948 I APP : at android.media.MediaPlayer._setDataSource(Native Method) 09-25 19:51:03.133 8891 8948 I APP : at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1133) 09-25 19:51:03.133 8891 8948 I APP : at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1118) 09-25 19:51:03.133 8891 8948 I APP : at com.rho.notification.NotificationSingleton.playFile(NotificationSingleton.java:168) 09-25 19:51:03.133 8891 8948 I APP : at com.rho.notification.NotificationSingletonBase$playFileTask.run(NotificationSingletonBase.java:106) 09-25 19:51:03.133 8891 8948 I APP : at com.rhomobile.rhodes.api.MethodExecutor.run(MethodExecutor.java:11) 09-25 19:51:03.133 8891 8948 I APP : E 09/25/2016 19:51:03:133 000022f4 MethodResult| Callback: , data: ; Tab id: -1; resultType: typeError; result: "null" 09-25 19:51:03.134 8891 8948 I APP : I 09/25/2016 19:51:03:133 000022f4 APP| App error: 09-25 19:51:03.134 8891 8948 I APP : lib/RhoNotificationApi.rb:53:in playFile' 09-25 19:51:03.134 8891 8948 I APP : lib/RhoNotificationApi.rb:53:inplay_file' 09-25 19:51:03.134 8891 8948 I APP : apps/app/Animation/animation_controller.rb:273:in draw' 09-25 19:51:03.134 8891 8948 I APP : lib/rho/rhocontroller.rb:101:inserve' 09-25 19:51:03.134 8891 8948 I APP : lib/rho/rhoapplication.rb:217:in serve' 09-25 19:51:03.134 8891 8948 I APP : lib/rho/rho.rb:836:inserve' 09-25 19:51:03.135 8891 8948 I APP : I 09/25/2016 19:51:03:135 000022f4 HttpServer| GC Start. 09-25 19:51:03.153 8891 8891 W cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 8891 09-25 19:51:03.162 8891 8891 I APP : I 09/25/2016 19:51:03:162 000022bb WebViewSingleton| onNavigateComplete <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 09-25 19:51:03.162 721 721 I MSM-irqbalance: Decided to move IRQ115 from CPU0 to CPU3 09-25 19:51:03.244 514 628 E ThermalEngine: ==== Enter sched_bmhb_cs_gov -> vs_temp = 305 === 09-25 19:51:03.250 8891 8948 I APP : I 09/25/2016 19:51:03:250 000022f4 HttpServer| GC End.

The most relevant point it seems is the line:

RhoFileApi| Can not open file descriptor: /public/audio/xing4.mp3: open failed: ENOENT (No such file or directory)

Which seems to indicate a missing file or bad location, but that is most certainly where my file resides.

I've found some posts that seem to be similar issues here:

https://developer.zebra.com/thread/4416

https://developer.zebra.com/thread/1787

But their solutions did not work. I didn't try making a folder explicitly called "alerts" as opposed to "audio" in the public folder, but I can't see why that would matter.


Solution

  • Fixed now. For those coming later, the problem was that the file location needs to be referenced from absolute position, which can be done thusly:

    Rho::Notification.playFile( Rho::Application.appsBundleFolder + "/public/audio/" + $audio_file + ".mp3", "audio/x-mp3")