How to play m3u audio stream in iOS app

后端 未结 2 411
走了就别回头了
走了就别回头了 2020-12-19 18:59

I\'m trying to create an iOS/iPhone radio app using Xcode 4.5.2.

I wanted to stream @\"http://xx.xxxxxxx.com/8111/radio.m3u\" with play, pause, volume control and ab

相关标签:
2条回答
  • 2020-12-19 19:41

    There are Two way to achieve this.

    1. You can directly load you URL in UIWebView and it will properly.
    2. You can also use MPMoviePlayerController.
    0 讨论(0)
  • 2020-12-19 19:45

    Create a "MPMoviePlayerController *player" as a strong object in your ViewController.

    So you code would look something like below:

    @interface ViewController ()
    {
        UISlider *volumeSlider;
        MPMoviePlayerController *player;
    }
    
    @end
    
    
    - (IBAction)playButtonPressed;
    {
        NSString *urlAddress = @"http://xxxxxxx.com/8111/listen.m3u";
        NSURL *url = [NSURL URLWithString:urlAddress];
    
        if(nil != player)
        {
          player = nil; // Alternatively you can stop and restart with the different stream.
        }
    
        player = [[MPMoviePlayerController alloc]initWithContentURL:url];
        player.movieSourceType = MPMovieSourceTypeStreaming;
        [player prepareToPlay];
        self.myPlayer = player;
        [self.view addSubview:self.myPlayer.view];
        [self.myPlayer play];
    }
    
    0 讨论(0)
提交回复
热议问题