I'm trying to use AVPlayer in my app, i made a test application and it works perfectly, but then when i tried to implement the same AVPlayer in my real app it crashes with these two errors :

This is LiveViewController.h:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface LiveViewController : UIViewController<AVAudioPlayerDelegate>
@property (strong, nonatomic) AVPlayer *audioPlayer;
@property (strong, nonatomic) IBOutlet UIButton *playPauseBtn;
- (IBAction)playAudio:(id)sender;
@end
And this is LiveViewController.m:
#import "LiveViewController.h"
@interface LiveViewController ()
@end
@implementation LiveViewController
NSURL *urlStream;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlAddress = @"http://198.178.123.23:8662/stream/1/;listen.mp3";
urlStream = [NSURL URLWithString:urlAddress];
self.audioPlayer = [AVPlayer playerWithURL:urlStream];
NSError *error;
if (error)
{
NSLog(@"Error in audioPlayer: %@",
[error localizedDescription]);
} else {
[_audioPlayer prepareForInterfaceBuilder];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playAudio:(id)sender {
if(self.audioPlayer.rate > 0 && self.audioPlayer.error == nil){
[self.audioPlayer pause];
NSLog(@"Hello there, trying to stop playing!");
[self.playPauseBtn setImage:[UIImage imageNamed:@"play_button"] forState:UIControlStateNormal];
}else{
self.audioPlayer = [AVPlayer playerWithURL:urlStream];
[self.audioPlayer play];
NSLog(@"Hello there, trying to play!");
[self.playPauseBtn setImage:[UIImage imageNamed:@"pause_button"] forState:UIControlStateNormal];
}
}
-(void)audioPlayerDidFinishPlaying:
(AVAudioPlayer *)player successfully:(BOOL)flag
{
}
-(void)audioPlayerDecodeErrorDidOccur:
(AVAudioPlayer *)player error:(NSError *)error
{
}
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player
{
}
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)player
{
}
@end
What are these errors and how can i fix them ?
NOTE: i searched for those errors and didn't find a solution.
Solution: add AVFoundation.framework to your build phases in your project.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With