同时使用AVAudioPlayer和MPMoviePlayerController [英] Using AVAudioPlayer and MPMoviePlayerController simultaneously

查看:49
本文介绍了同时使用AVAudioPlayer和MPMoviePlayerController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要同时使用 AVAudioPlayer MPMoviePlayerController ,即可以在播放背景循环的同时播放电影.
当电影开始播放时,我的bg音乐循环停止工作,因此我尝试停止bg音乐循环并开始播放电影,而当电影停止播放时,再次开始播放bg循环,但这也不起作用.

I need to use AVAudioPlayer and MPMoviePlayerController simultaneously i.e play a movie while the background loop is playing is it possible.
My bg music loop stops working when a movie starts playing , so I tried to stop the bg music loop and start the movie and when movie stops, start playing the bg loop again but this is also is not working.

推荐答案

实际上,从3.x开始就可以实现.我曾经在一个应用程序中执行过此操作,它与任何背景或任何其他新的iOS功能无关.您只需要正确配置音频会话.如果您确定音频播放器和视频播放器都在使用环境音频会话,则可以.

In fact it is achievable from 3.x onwards. I had once done this in one of my applications and its got nothing to do with any backgrounding or any other new iOS features. You just need to configure the audio sessions properly. If you make sure that both your audio player as well as the video player are using the ambient audio session it is possible.

在开始播放 AVAudioPlayer 之前,请将音频会话的类别设置为 AVAudioSessionCategoryAmbient .这是系统范围内的通用音频会话.这样可以播放其他声音,例如来自iPod应用程序的声音.

Prior to starting your AVAudioPlayer to play, set the category of audio session to AVAudioSessionCategoryAmbient. This is the system wide common audio session. This allows other sounds to play along such as the sound from the iPod application.

如果您使用的是iOS 3.2或更高版本的 MPMoviePlayerController ,请确保将 useApplicationAudioSession 设置为 NO .这样可以确保播放其他声音.这是iOS早期版本中的默认设置.

In case you are using the MPMoviePlayerController from iOS 3.2 or above make sure you set the useApplicationAudioSession to NO. This ensures other sounds to play along. It is the default in earlier versions of iOS.

这篇关于同时使用AVAudioPlayer和MPMoviePlayerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆