avplayer is not playing the URL

前端 未结 5 1451
长情又很酷
长情又很酷 2021-02-04 15:00

I am using avplayer for play audio url, but it is not working, I don\'t know where i am wrong

NSString *radioURL = @\"https://www.example.com\";

radioPlayer = [         


        
5条回答
  •  我在风中等你
    2021-02-04 15:44

    You are doing good but your method need to correct on one place.Check using the below method:

    NSURL *audioURL = [NSURL URLWithString:radioURL];
    NSData *audioData = [NSData dataWithContentsOfURL:audioURL];
    self.audioPlayer = [[AVAudioPlayer alloc] initWithData:audioData error:nil];
    self.audioPlayer.numberOfLoops = -1;
    self.audioPlayer.delegate = self;
    [self.audioPlayer prepareToPlay];
    self.audioPlayer.volume=1.0;
    [self.audioPlayer autorelease];
    [self.audioPlayer Play];
    

    and add proper delegate methods for AVAudioPlayer.

提交回复
热议问题