简体   繁体   English

音频播放器可以在后台的iOS模拟器上运行,但不能在iOS设备上使用(相同版本)

[英]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.

相关问题 音频播放器可在模拟器中工作,但不能在iOS设备上工作 - Audio player works in simulator but not on iOS device iOS背景音频流(m3u)在设备上不起作用(但在模拟器中可以) - iOS background Audio Stream (m3u) doesn't work on device (but does in simulator) 背景音频在iOS模拟器上可运行,但不能在设备上运行 - background audio working on iOS simulator but not device Xamarin.ios 不适用于真正的 iOS 设备,但它适用于模拟器 - Xamarin.ios does NOT work on real iOS device but it works on Simulator 在后台录制IOS模拟器视频和模拟器音频 - Record IOS Simulator video and simulator audio in background Google Map ios SDK无法在设备中使用,但可以在模拟器中使用 - Google Map ios sdk does not work in device, but work in simulator 使用ffmeg提取的电视音频在iOS中不起作用(但在模拟器中有效) - TV audio extracted using ffmeg does not work in iOS (but it works in the simulator) 音频和振动在模拟器中工作,而不是在ios设备上 - Audio and vibrate working in simulator not on ios device iOS在模拟器上成功播放音频,但在设备上失败 - iOS play audio success on simulator but fail on device UIContentSizeCategoryDidChangeNotification不适用于模拟器iOS 9.3,可在设备上运行 - UIContentSizeCategoryDidChangeNotification not working on simulator iOS 9.3, does work on device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM