如何处理iphone的中断 [英] how to handle the interruption in iphone

查看:152
本文介绍了如何处理iphone的中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iphone中的AVAudioPlayer有问题,当我的ipod锁定(睡眠)时,歌曲停止。我在编码制作音乐时做的是继续启动甚至ipod锁定(睡眠)。
请帮帮我

I have problem with AVAudioPlayer in iphone when ever the my ipod is lock(sleep) the song is stop.What I have do in coding for making music is continueslu start even the ipod is lock(sleep) . please help me

我是全新的。

推荐答案

您可以使用不同的类别来执行此操作:

You can use different categories to do this:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{  
    ...

     // allows you to play when the screen is locked and also when the ringer is set to silent
    [[AVAudioSession sharedInstance] setDelegate: self];
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];

    ...
}

如果你想继续当您的应用程序被暂停到后台时(例如,用户点击主页按钮)在iOS4上播放声音,然后您还需要将其添加到 info.plist 文件(以纯文本模式显示):

If you want to continue to play the sound on iOS4 when your app gets suspended into the background (for instance, the user hits the home button), then you also need to add this to your info.plist file (this shows it in plain text mode):

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>

顺便说一句,如果你真的需要处理像这样的中断您的问题标题说(如电话等),在 AVAudioPlayer class

By the way, if you ever really needed to handle an interruption like your question title said (like a phone call, etc), there is a delegate method for that in the AVAudioPlayer class:

- (void) audioPlayerBeginInterruption: (AVAudioPlayer *) player { }

- (void) audioPlayerEndInterruption: (AVAudioPlayer *) player { }

这篇关于如何处理iphone的中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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