Mp3/Wav Android 在 Rhomobile 5.4 中播放
Mp3/Wav Playback in Rhomobile 5.4 on Android
我有一个应用试图使用以下代码播放一个小声音文件:
Alert.play_file("/public/audio/" + $audio_file + ".mp3", "audio/x-mp3") if Configuration.current.audio_prompt?
当我使用此代码时,应用会抛出一个 "Server Error",如下所示:
我曾尝试使用媒体播放器 API 而不是警报 API,但收到了基本相同的错误。
这是编解码器问题吗?
对于 Wav 文件(是的,在那些行中正确指向 wav 文件而不是 mp3)不会抛出错误,但不会播放声音本身。
编辑
在这个错误期间我终于能够得到一些 logcat 数据,并收到了这个:
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:in
play_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:in
serve'
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:in
serve'
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.
似乎最相关的一点是:
RhoFileApi|无法打开文件描述符:/public/audio/xing4.mp3:打开失败:ENOENT(没有这样的文件或目录)
这似乎表明文件丢失或位置不正确,但这肯定是我的文件所在的位置。
我在这里发现了一些似乎是类似问题的帖子:
https://developer.zebra.com/thread/4416
https://developer.zebra.com/thread/1787
但是他们的解决方案没有奏效。我没有尝试在 public 文件夹中创建一个明确名为 "alerts" 而不是 "audio" 的文件夹,但我不明白为什么这很重要。
现已修复。对于后来的人来说,问题是文件位置需要从绝对位置引用,可以这样做:
Rho::Notification.playFile( Rho::Application.appsBundleFolder + "/public/audio/" + $audio_file + ".mp3", "audio/x-mp3")
我有一个应用试图使用以下代码播放一个小声音文件:
Alert.play_file("/public/audio/" + $audio_file + ".mp3", "audio/x-mp3") if Configuration.current.audio_prompt?
当我使用此代码时,应用会抛出一个 "Server Error",如下所示:
我曾尝试使用媒体播放器 API 而不是警报 API,但收到了基本相同的错误。
这是编解码器问题吗?
对于 Wav 文件(是的,在那些行中正确指向 wav 文件而不是 mp3)不会抛出错误,但不会播放声音本身。
编辑
在这个错误期间我终于能够得到一些 logcat 数据,并收到了这个:
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:in
play_file' 09-25 19:51:03.134 8891 8948 I APP : apps/app/Animation/animation_controller.rb:273:indraw' 09-25 19:51:03.134 8891 8948 I APP : lib/rho/rhocontroller.rb:101:in
serve' 09-25 19:51:03.134 8891 8948 I APP : lib/rho/rhoapplication.rb:217:inserve' 09-25 19:51:03.134 8891 8948 I APP : lib/rho/rho.rb:836:in
serve' 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.
似乎最相关的一点是:
RhoFileApi|无法打开文件描述符:/public/audio/xing4.mp3:打开失败:ENOENT(没有这样的文件或目录)
这似乎表明文件丢失或位置不正确,但这肯定是我的文件所在的位置。
我在这里发现了一些似乎是类似问题的帖子:
https://developer.zebra.com/thread/4416
https://developer.zebra.com/thread/1787
但是他们的解决方案没有奏效。我没有尝试在 public 文件夹中创建一个明确名为 "alerts" 而不是 "audio" 的文件夹,但我不明白为什么这很重要。
现已修复。对于后来的人来说,问题是文件位置需要从绝对位置引用,可以这样做:
Rho::Notification.playFile( Rho::Application.appsBundleFolder + "/public/audio/" + $audio_file + ".mp3", "audio/x-mp3")