Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_AVPlayer"

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 :

Xcode ScreenShot

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.

like image 239
ANA Avatar asked Oct 24 '25 17:10

ANA


1 Answers

Solution: add AVFoundation.framework to your build phases in your project.

Hope this helps.

like image 66
Fadi Obaji Avatar answered Oct 26 '25 07:10

Fadi Obaji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!