MPMoviePlayerController Audio show "Done" Button - ios

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

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

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

Related

AVPLAYER VIDEO BUFFER FULL??? (How To Reset/Empty The Buffer)

So I'm using AVPlayerViewController and what i'm doing to load the video is basically this:
I have a large number of videos in my database, I make a call to the db to retrieve the next video after the current video has finished playing, the issue I think may have to do with the buffer being full? After looking around on stack & the internet I couldn't find an answer that helped me.
I'm trying to find out how can I reset the buffer after each video is played, or atleast know when the buffer is out of space so that I can display an image or something while the buffer loads, so then I can make a call to continue displaying videos. Below is my code for the AVPlayerViewController.
AVPlayerViewController *playerViewController = [[AVPlayerViewController
alloc] init];
playerViewController.player = [AVPlayer #"www.videoURL.com"];
self.avPlayerViewcontroller = playerViewController;
[playerViewController.view setFrame: userView.bounds];
[userView addSubview:playerViewController.view];
self.avPlayerViewcontroller.player.volume = 0.0;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(volumeChanged:)
name:#"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
[playerViewController.player play];
[userImageView setHidden:NO];
Edit:1) I'm about to play about 15-25 videos before the video play gives me this:
Edit:2) But if I close the app and then re-open it, the videos play on the app like nothings wrong. I'm not really sure whats going on.
For anyone that encounters this same scenario, The issue for me was inside of the the same block that I was making my API call I was initializing this:
AVPlayerViewController *playerViewController =
[[AVPlayerViewController alloc] init];
AVPlayerViewController was (STRONG) reference causing a retain cycle within the block, so each time I made an API call to grab a new video I was init a whole new AVPlayerViewController without releasing the previous. Along with that, I found that I had other objects within the API success response were being referenced strong as well. So I went back made those a WEAK reference and then I moved
AVPlayerViewController *playerViewController =
[[AVPlayerViewController alloc] init];
To the view did load method, so it's initialized ONCE instead of everytime a new video URL comes through.
It took me all day to figure out what was going one, because after looking at other users having problems with this, I was so focused on "BUFFERING" or running out of buffering was the culprit, but comes to find out it was just bad implementation of objects and misplacements.
Good luck to future programmers.

Objective-C: Making AVPlayer plays in all the app controllers (or in the background)

I'm making a news iOS app, i want to implement a live audio streaming in all the pages like the picture below:
The orange view is a UIView that says "Live Streaming" (in Arabic), it exists in all the viewControllers, i want to let the AVPlayer plays when the user clicks on it and still plays even if the user navigates to other viewControllers.
I can't seem to find a good solution or tutorial about this, sorry if this is a noob question cause i'm new to iOS.
So how can i do that ? and where(in which viewController) should i put the AVPlayer declaration ?
Thanks in advance.
If you are testing in the simulator, the change of views will not continue the audio in the background. If it is not working your device try this:
NSURL *url = [NSURL URLWithString: yourURLHere];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVPlayer *audioPlayer = [AVPlayer playerWithPlayerItem:playerItem];
//This enables background music playing
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[audioPlayer play];
Place this code in your viewDidLoad method, before [super viewDidLoad];
I found two links that exaplin some of the issues on this:
Play Music in Background
Play Audio from Internet
If this does not work, I would recommend placing a bounty on the question as it seems your issue's are a little more in depth than a simple solution.
I found the solution, i had to make a singleton class.
The singleton class allow only one object to be used in the entire iOS application by all the ViewControllers.
And i did put all the needed methods like play and pause in the singleton class and i accessed them from all the ViewControllers.
If anybody wants an example, please ask in the comments.

radio streaming without MPMoviePlayerController

i am currently doing a small radio shoutcast for android and ios with kony.
everything is fine with android but for ios, i am creating a library to play the shoutcast.
Unfortunatly, it seems that the player of MPMoviePlayerController need to be set as a subview to work and i am unable to do that.
does anybody know an other solution to play a shoutcast on IOS?
I don't know about shoutcast but I imagine its similar to SoundCloud in which you use the API to parse the stream URL? If I'm right in thinking that then you simply need to put the URL into an NSURL and make sure to tell the MPMoviePlayerController the source, like so...
radioPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:YOUR_SHOUTCAST_STREAM_URL]];
radioPlayer.movieSourceType = MPMovieSourceTypeStreaming;
Then simply play
[radioPlayer prepareToPlay];
Hope that helps :)

buffer video before playing it on iphone

I'm doing some testing which during I would like to:
- Take a video that is in the app folder
- load that video to memory (buffer it)
- play the bufferd frames from the memory
All made on iPhone
Actually,
I would like to play a video from memory.
(I also want to load the video to memory by frames).
I hope it clear enough.
How can I accomplish this?
Tnx
EDIT:
Maybe I can point my question a little more..
I have a server that streams video via UDP (let's say that for the simuloation I'm using VLC to stream via UDP).
What do I have to do and implement in order to get the UDP stream from VLC and display it on the screen of my I device (of course i'm talking about writing code and not using VLC streamer :-) ).
Hope that's better and that I'll get some answers now.
Tnx
A video has to be buffered only if you receive the video from a server over internet via packets/Streams.
Else you can just play the video using below code:-
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"yourVideo" ofType:#"yourVideoType" inDirectory:#""]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[player view] setFrame:[self.view bounds]];
[self.view addSubview:[player view]];
[player play];
[player release];
You can implement the notification MPMoviePlayerLoadStateDidChangeNotification, if you are playing the videos after fetching over some data service.(GPRS,2G, Internet.)

MPMoviePlayerController for remote file on Amazon S3

My app allows videos to be displayed in UITableViewCells on iOS.
I'm currently storing my video files in Amazon S3 and utilizing Cloudfront. I got this code from the Apple docs:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
I have implemented this code pretty much exactly into my own app. For some reason, it does not seem to work for me. I think it may have something to do with not having JWPlayer installed in my S3 bucket.
My question is: In order to display a video in the app that allows playing while loading the remaining contents of the video in the background, do I need to have JWPlayer in my S3 bucket?...or is this unnecessary given the use of MPMoviePlayerController.
Thanks!
Well the problem is that the MPMoviePlayerController can't play that file because is not streamed. [[MPMoviePlayerController alloc] initWithContentURL: myURL]; expects a network stream, in your case is not a network stream. What you could do, is download the file and save it in your app documents files and play it from there.

Resources