我正在使用 Phonegap 为网络收音机创建播放器。
播放流效果很好,但我无法停止流。当我点击停止按钮时,我在日志中有此消息:
AudioPlayer 错误:在无效状态期间调用 stopPlaying():4
在屏幕上我有一个“未定义”的错误。似乎我的变量my_media
没有定义。
这是我的代码:
var src="http://stream.muzeeli.fr/ange";
var my_media = null;
function playAudio(src) {
if (my_media == null) {
my_media = new Media(src, onSuccess, onError);
}
my_media.play();
}
function stopAudio() {
if (my_media) {
my_media.stop();
}
}
$(document).bind('pageinit',function(){
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
$('#play').click(function(event){
playAudio(src);
});
$('#stop').click(function(event){
stopAudio();
});
}
});
我添加了一个日志文件。似乎媒体的状态没有很好地更新,并且始终处于 MEDIA_NONE 状态。所以 stop 不能被调用。
E/MediaPlayer(23457): mOnSeekCompleteListener is null. Failed to send MEDIA_SEEK_COMPLETE message.
V/MediaPlayer(23457): buffering 0
V/MediaPlayer(23457): callback application
V/MediaPlayer(23457): back from callback
V/MediaPlayer(23457): message received msg=200, ext1=703, ext2=193
W/MediaPlayer(23457): info/warning (703, 193)
V/MediaPlayer(23457): callback application
V/MediaPlayer(23457): message received msg=200, ext1=701, ext2=0
W/MediaPlayer(23457): info/warning (701, 0)
V/MediaPlayer(23457): callback application
V/MediaPlayer(23457): back from callback
E/MediaPlayer(23457): mOnBufferingUpdateListener is null. Failed to send MEDIA_BUFFERING_UPDATE message.
I/MediaPlayer(23457): Info (703,193)
E/MediaPlayer(23457): mOnInfoListener is null. Failed to send MEDIA_INFO message.
I/MediaPlayer(23457): Info (701,0)
E/MediaPlayer(23457): mOnInfoListener is null. Failed to send MEDIA_INFO message.
V/MediaPlayer(23457): message received msg=100, ext1=1, ext2=-110
E/MediaPlayer(23457): error (1, -110)
V/MediaPlayer(23457): callback application
V/MediaPlayer(23457): back from callback
E/MediaPlayer(23457): Error (1,-110)
E/MediaPlayer(23457): mOnErrorListener is null. Failed to send MEDIA_ERROR message.
D/AudioPlayer(23457): on completion is calling stopped
D/CordovaLog(23457): playAudio():Audio Success
D/CordovaLog(23457): file:///android_asset/www/js/muzeeli.js: Line 40 : playAudio():Audio Success
I/Web Console(23457): playAudio():Audio Success at file:///android_asset/www/js/muzeeli.js:40
有人有想法吗?
最好的,
阿兰