Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController Audio show "Done" Button

I use the MPMoviePlayerController to Play an Audio Stream. My code follows the example at:

http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

Everything works fine, but while the stream is playing there is no "done" button to close the Player.

I tested it first with a normal .mp3 file. With the file the only possibility I found is to skip to the end, so the player gets the MPMoviePlayerPlaybackDidFinishNotification notification (but this won't work on an endless stream, since there is no timeline to skip to the end).

I tried various styles like [mp setControlStyle:MPMovieControlStyleFullscreen]; with no succes.

In the documentation at MPMoviePlayerController Class stands:

This class plays any movie or audio file supported in iOS. This includes both streamed content and fixed-length files

Is there a possibility to display that button while playing some audio content, or has anyone another solution?

I tried to show you an screenshot but "new users can only post a maximum of two hyperlinks".

like image 201
crashbus Avatar asked Dec 06 '22 23:12

crashbus


2 Answers

i found a solution by my self.

Using the MPMoviePlayerViewController class, instead of MPMoviePlayerController solved the problem:

NSString *path = @"http://yourstreamingurl.com/stream.m3u";

MPMoviePlayerViewController* mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:path]];

mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;  
[self presentModalViewController:mpviewController animated:YES];
[[mpviewController moviePlayer] play];
like image 112
crashbus Avatar answered Feb 08 '23 23:02

crashbus


For playing file locally, remove

mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;  

Other wise it will return

Terminating app due to uncaught exception NSInvalidArgumentException reason An AVPlayerItem cannot be associated with more than one instance of AVPlayer
like image 28
hook38 Avatar answered Feb 08 '23 22:02

hook38