Get an audio stream from URI and play it on iPhone

前端 未结 4 972
轻奢々
轻奢々 2020-12-08 05:24

I would like to get an audio stream from URL and play it on iPhone. Unfortunately, there is only C# example of how to play that stream, but I need a realization on Objective

4条回答
  •  一整个雨季
    2020-12-08 06:25

    NSString* resourcePath = url; //your url
    NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
    NSError *error;
    
    app.audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
    app.audioPlayer.numberOfLoops = 0;
    app.audioPlayer.volume = 1.0f;
    [app.audioPlayer prepareToPlay];
    
    if (app.audioPlayer == nil)
        NSLog(@"%@", [error description]);
    else
        [app.audioPlayer play];
    

提交回复
热议问题