在第一視圖停止我從一開始Audioplayer不會從其他視圖
@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];
}
好吧,IHAVE很多意見創建音頻播放器和負載,我高興的是,MUSIK發揮始終都無所謂在什麼看法我的工作。但我需要在其他(我的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];}
我在哪裏弄錯了?
嘗試:1)明確設置mp3 p roperty通過使用[self setMp3:...]; 2)使用大於0的數字作爲循環的數量3)使用[_splashViewController.mp3 stop]; –
2和3沒有幫助,約1 - 我不明白^我必須做什麼=( – Neznajka
替換行= [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; with [self setMp3:[[ AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]]; –