針對此問題,我的做法是在AudioStreamer.h文件新加入一個屬性
@PRoperty (nonatomic,strong) NSURL *musicUrl;
和一個單例方法:
+(id)sharedStreamer;
同時在AudioStreamer.m文件中實現單例方法和musicURL的set方法
+(id)sharedStreamer{
static AudioStreamer *streamer = nil;
static dispatch_once_t tocken;
dispatch_once(&tocken, ^{
streamer = [[AudioStreamer alloc] init];
});
return streamer;
}
-(void)setMusicUrl:(NSURL *)musicUrl{
url = musicUrl;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruptionChangeToState:) name:ASAudiosessionInterruptionOccuredNotification object:nil];
}
這樣后在創建streamer對象的時候變可以像下面那樣做:
streamer = [AudioStreamer sharedStreamer];
[streamer stop];
streamer.musicUrl = url;
[streamer start];
那么問題解決。。晚安!
|
新聞熱點
疑難解答