MPMoviePlayerController Audio show “Done” Button

☆樱花仙子☆ 提交于 2019-12-05 01:30:03

问题


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".


回答1:


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];



回答2:


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


来源:https://stackoverflow.com/questions/5031853/mpmovieplayercontroller-audio-show-done-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!