Arash khangaldi
Arash khangaldi

Reputation: 110

Playing Stream .m3u8 Audio File in iOS

I am confused about this. I have an URL which contains a .m3u8 file in it and when I try to stream the URL with:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

[player setControlStyle:MPMovieControlModeVolumeOnly];
[player setFullscreen:YES];
[player prepareToPlay];
[player play];

It seems I can't because nothing starts playing. But when I use:

 MPMoviePlayerViewController* controller = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentViewController:controller animated:YES completion:nil];

The viewcontroller starts playing the file. What's the difference? Why can't I do it in my viewcontroller? Thanks in advance.

Upvotes: 0

Views: 1531

Answers (2)

Unheilig
Unheilig

Reputation: 16292

MPMoviePlayerController lets you start playing, stopping and streaming of the content, which is meant to be incorporated into your own view hierarchy.

Since iOS 3.2 MPMoviePlayerViewController became available, which handles the presentation for you.

In your code above, for the first case, it is not added to the view hierarchy.

Ex:

[self.view addSubview:player.view]; 

Another difference is MPMoviePlayerController is a property of MPMoviePlayerViewController.

Think of MPMoviePlayerController as a player that gives you the controls and MPMoviePlayerViewController provides you, in addition to controls, also the presentation.

Hope this helps.

Upvotes: 1

gran33
gran33

Reputation: 12951

In your first code section you just have a MPMoviePlayerController, you should present it on screen, and actually add the MPMoviePlayerController View to your presented UIVIewcontroller's View

[self.view addSubView:player.view] 

In your second code section you have actually UIViewController With MPMoviePlayerController in it as composition design pattern .

Upvotes: 1

Related Questions