在第一个视图中,我创建音频播放器并从头开始加载
@interface SplashViewController : UIViewController
...
@property (strong, nonatomic) AVAudioPlayer *mp3;
...
- (void)viewDidLoad
{
[super viewDidLoad];
[self viewDidAppear:YES];
NSString *path = [[NSBundle mainBundle]pathForResource:@"sooner" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:path];
NSError *error;
mp3 = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
[mp3 setNumberOfLoops:-1];
[mp3 setVolume:1.0];
[mp3 play];
}
好的,我有很多观点,我很高兴音乐播放总是不管我工作的观点。但我需要在其他(我的 SettingView)中停止音乐。我在 SettingView 中有下一个代码,但我没有结果 - 音乐播放和播放,不想停止
@class SplashViewController;
@interface SettingsViewController : UIViewController
@property (strong, nonatomic) SplashViewController *splashViewController;
________________________________________________________
#import "SplashViewController.h"
...
@implementation SettingsViewController
@synthesize pauseMusik; //UISwitch
@synthesize splashViewController = _splashViewController;
...
-(IBAction)playPauseMusik:(id)sender
{
if(!self.splashViewController)
self.splashViewController = [[SplashViewController
alloc]initWithNibName:@"SplashViewController" bundle:nil];
if (pauseMusik.on) {
[self.splashViewController.mp3 play];
}
else
[self.splashViewController.mp3 stop];}
我哪里做错了?