我已经搜索过这个答案,但没有找到。
当我的 iPhone 应用程序启动时,我会在后台播放音乐。但我想要一个按钮,以便用户可以将音乐静音。应用程序内也有音效,因此滑动设备侧面的静音按钮不会切断它。
这是我为 AVAudioPlayer 提供的当前代码。
- (void)viewDidLoad{
#if TARGET_IPHONE_SIMULATOR
//here code for use when execute in simulator
#else
//in real iphone
NSString *path = [[NSBundle mainBundle] pathForResource:@"FUNKYMUSIC" ofType:@"mp3"];
AVAudioPlayer *TheAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
TheAudio.delegate = self;
[TheAudio play];
TheAudio.numberOfLoops = -1;
#endif
}
任何人都可以帮我编写一个简单按钮所需的代码,以简单地停止音乐并重新开始。
提前致谢。