为什么声音不播放?
所以这是我的代码:
按一下按钮:
-(void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
[self dismissModalViewControllerAnimated:YES];
self.selectedSong = mediaItemCollection;
NSLog(@"Selected song: %@", self.selectedSong);
}
稍后:
-(void)waitUntilSpeechIsDone {
NSLog(@"Test");
if ([audio isEqualToString:@"Music"]) {
if ([musicWhenToStart isEqualToString:@"Before"]) {
NSLog(@"Test");
NSLog(@"Selected song: %@", self.selectedSong);
[self.musicPlayer stop];
[self.musicPlayer setQueueWithItemCollection:self.selectedSong];
[self.musicPlayer play];
}
}
}
它的定义为:
@interface RewriteViewController : UIViewController <MPMediaPickerControllerDelegate> {
MPMediaItemCollection *selectedSong;
}
@property(nonatomic,retain) MPMusicPlayerController *musicPlayer;
@property(nonatomic,retain) MPMediaItemCollection *selectedSong;
MPMediaItemCollection *selectedSong;
然后两者都在 .m 文件中综合。
好吧,上半场顺利度过。 NSLog 返回类似“选定的歌曲:”的内容,然后 NSLog 返回“测试”(我把它放在那里,这样我知道它已经到了那么远,以防它由于某种原因在下一行崩溃)。然后,当它到达下一行时,它返回“选定的歌曲:(空)”。
有什么想法吗?
编辑:两者都在 dealloc 中释放。
So this is the code I have:
At the press of a button:
-(void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
[self dismissModalViewControllerAnimated:YES];
self.selectedSong = mediaItemCollection;
NSLog(@"Selected song: %@", self.selectedSong);
}
Later on:
-(void)waitUntilSpeechIsDone {
NSLog(@"Test");
if ([audio isEqualToString:@"Music"]) {
if ([musicWhenToStart isEqualToString:@"Before"]) {
NSLog(@"Test");
NSLog(@"Selected song: %@", self.selectedSong);
[self.musicPlayer stop];
[self.musicPlayer setQueueWithItemCollection:self.selectedSong];
[self.musicPlayer play];
}
}
}
It's defined as:
@interface RewriteViewController : UIViewController <MPMediaPickerControllerDelegate> {
MPMediaItemCollection *selectedSong;
}
@property(nonatomic,retain) MPMusicPlayerController *musicPlayer;
@property(nonatomic,retain) MPMediaItemCollection *selectedSong;
MPMediaItemCollection *selectedSong;
Then both are synthesized in the .m file.
Ok, so it gets through the first half fine. The NSLog returns something like "Selected song: " Then NSLog returns "Test", (i put that there so i know it's got that far in case it crashes at the next line for some reason). Then when it gets to the next line it returns "Selected song: (null)".
Any ideas why?
EDIT: Both are released in dealloc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您的界面文件,您似乎声明了
MPMediaItemCollection *selectedSong;
两次:/我不确定这是否是发布问题时的拼写错误,但这可能与此有关。您的崩溃很可能与selectedSong
在您没有预料到的某个时刻被释放有关,并且错误的声明可能会导致这种情况。Looking at your interface file, it appears you are declaring
MPMediaItemCollection *selectedSong;
twice :/ I'm not sure if this was a typo in posting the question, but that might have something to do with it. You crash is most likely related toselectedSong
being released at some point when you don't expect it, and an bad declaration could be causing that.