[英]Audio player work on iOS simulator in Background but does not on iOS device (same version)
I am trying to play an audio streaming until application is in background. 我正在尝试播放音频流,直到应用程序在后台运行。
Here is the code : 这是代码:
var service;
if(isiOS4Plus()){
Ti.App.addEventListener('resumed',function(e){
if(service!=null){
if(winPlayer.controlStreamer)// if my controller (containing the audio player object) exists
{
//function that redeclare intervals and event listeners
winPlayer.controlStreamer.foregroundStreamer();
}
service.stop();
service.unregister();
}
});
Ti.App.addEventListener('pause',function(e){
if(winPlayer.controlStreamer)// if my controller (containing the audio player object) exists
{
//function that stop and remove intervals and event listeners
winPlayer.controlStreamer.backgroundStreamer();
}
service = Titanium.App.iOS.registerBackgroundService({url:'/player/sound.js'});
Ti.API.info("registered background service = "+service);
});
}
Audio player object is intitialized before in this method : 此方法之前已初始化音频播放器对象:
this.streamer=Titanium.Media.createAudioPlayer({url:this.url_stream_stetienne,bufferSize:1000000});
Here is my problem : when i running app on iOS Simulator (iOS 5.0), stream player continue playing (what I want it does), but when I test it on iOS Device (iOS 5.0) sound volume decrease and player stop. 这是我的问题:当我在iOS Simulator(iOS 5.0)上运行应用程序时,流播放器继续播放(我想要它做什么),但是当我在iOS设备(iOS 5.0)上对其进行测试时,音量降低并且播放器停止。
Note : the file info.plist contains the following lines : 注意:文件info.plist包含以下几行:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
And I now with alert boxes that events are correctly triggered and handled. 现在,我在警报框中显示事件已正确触发和处理。
Ok, it is not a bug : If you want to play an audio streaming (like a webradio stream) on iOS, you have to set the "audioSessionMode" parameter to "Titanium.Media.AUDIO_SESSION_MODE_PLAYBACK" (maybe others values are correct ?) in your audioPlayer instance. 好的,这不是错误:如果您想在iOS上播放音频流(如网络广播流),则必须将“ audioSessionMode”参数设置为“ Titanium.Media.AUDIO_SESSION_MODE_PLAYBACK”(也许其他值正确吗?)在您的audioPlayer实例中。
If you don't, streamer will work fine in background mode, but only if tested with iPhone simulator, not with device. 如果不这样做,则流光将在后台模式下正常工作,但仅在使用iPhone模拟器(而不是设备)进行测试的情况下。
Hope this helps somebody else. 希望这对其他人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.