嗨,我是 ios 的新手,我想制作一个播放收音机的应用程序,所以该应用程序运行良好,但是当我尝试将音量包含到应用程序时,它是 cruch 并给了我这个错误:
[AVPlayer setVolume:]: unrecognized selector sent to instance 0x9d4f500
2013-05-16 09:34:47.785 RadioFM[22061:12503] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVPlayer setVolume:]: unrecognized selector sent to instance 0x9d4f500'
这是我正在使用的源代码:
在 PlayerViewController.h 中:
@interface PlayerViewController : UIViewController
{ AVAudioPlayer *radioPlayer; IBOutlet UISlider *Volume; }
- (IBAction)Volume:(id)sender;
@property (nonatomic,retain) AVAudioPlayer *radioPlayer;
在 PlayerViewController.m 中:
@synthesize radioPlayer;
- (void)viewDidLoad
{
NSString *RadStream=<@Radio stream>;
NSURL *url=[NSURL URLWithString:RadStream];
NSError *error;
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
self.radioPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self.radioPlayer play];
[super viewDidLoad];
}
我有一个滑块视图,在这个滑块的操作上我有:
- (IBAction)Volume:(id)sender {
if (self.radioPlayer != nil)
{
self.radioPlayer.volume = Volume.value;
}
}
所以请任何人都可以帮助我吗?谢谢你提前。