简体   繁体   English

如何在iPhone App中管理背景声音?

[英]How to Manage Background Sound in iphone App?

I am playing a background sound using the AVAudioPlayer Framework. 我正在使用AVAudioPlayer Framework播放背景声音。 I have a play button and a pause button. 我有一个播放按钮和一个暂停按钮。 It works, but whenever I switch views and return to the main menu, it stops working. 它可以工作,但是只要我切换视图并返回主菜单,它就会停止工作。

-测量您的音乐运行时间,然后将NSTimer与音乐运行时间一起设置并将计时器设置为音频启动方法。将您的标志传递给第二个视图执行相同的操作。

set a loop , this probably means your music isnt long enough. 设置一个循环,这可能意味着您的音乐不够长。 say, //your avaudioplayer.numberOfLoops = -1 例如,//您的avaudioplayer.numberOfLoops = -1

that will make it keep on going, music will only stop IF you it finishes if you change view and music is not done it should stil go on. 这样一来,音乐就不会停止,只有当您更改视图并且未完成音乐时,音乐才能停止播放。 But if you want background music from when you start the app put your avaudioplayer code with the loop inside your app delegate bool did finish launching with options and inherit the method to stop it in the other view eg 但是,如果您想从启动应用程序时获取背景音乐,请在应用程序委托bool中放入带有循环的avaudioplayer代码,bool确实完成了带有选项的启动,并继承了在其他视图中将其停止的方法,例如

appDelegate *delegate = [[appDelegate alloc] init]; appDelegate * delegate = [[appDelegate alloc] init]; [appDelegate stop]; [appDelegate停止]; and make a stop method in the app delegate saying [music stop] or something like that 然后在应用程序委托中使用stop方法,说出[music stop]或类似的名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM