iosobjective-cavaudioplayeramr

AVAudioPlayer do not play AMR files


I ad using below code to download an AMR file from web and playing by AVAudioPlayer but all times I get the unrecongnize selector sent to instance error.

This is the method that start download and play:

- (IBAction)DisplayAudioPlayView:(id)sender 
{    
    [self InitializePlayer];   
}

-(void) InitializePlayer
{
    // Get the file path to the doa audio to play.
    NSString *filePath = [[ServerInteraction instance] getAudio:audioData.ID];

    // Convert the file path to a URL.
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: filePath];

    //Initialize the AVAudioPlayer.
    audioPlayer=  [AVPlayer playerWithURL:fileURL] ;
    audioPlayer.delegate= self; //THIS LINE CAUSE ERROR//

    // Preloads the buffer and prepares the audio for playing.
    [audioPlayer prepareToPlay];
    audioPlayer.currentTime = 0;

    [audioPlayer play]
}

Edit

Based on @Michael advise I change my code and this post I changed my code to this:

NSURL *fileURL = [[NSURL alloc] initWithString: @"http://www.domain1.com/mysound.mp3"];

//Initialize the AVAudioPlayer.
audioPlayer=  [AVPlayer playerWithURL:fileURL];
[audioPlayer play];

Now it played the sound but when I use http://maindomain.com/mysound.amr it is not playing the sound.


Solution

  • Check the following points: