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.
Related
My application is actually downloading a video I can easily read with MPMoviePlayerController. But now I have my video split and so on a segment form (meaning I receive a segment.init and then some other segments containing the video such as video_mp4_init.segment, video_mp4_0000.segment, video_mp4_0001.segment etc) in my bundle.
What I am looking for is some help about the way I need to read the bytes. So far I'm reading the same way I read a video:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"tos_mp4_media_0000" ofType:#"segment"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
A black screen launches then quit. I know MPMoviePlayer does not read .segment and I do guess this is not the way it should be done but I run out of ideas.
I'd find it a bit odd if MPMoviePlayer does not allow the reading of bytes but it might also be a problem. I can swap to another video reader if needed.
Any idea is welcome.
Edited for futher informations.
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 :)
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.)
Is there any way to play Video Streaming via URL in iOS native App which can not be downloaded or saved locally. I want to let the user watch video but he should not be able to download or save video locally (via 3rd party downloader apps).
Is above case can be possible in MPMoviePlayerController, MPMoviePlayerViewController or WebViewController?
Any suggestion will be appreciated.
It is possible via MPMoviePlayerViewController.
NSURL *url = [NSURL URLWithString:yourLink];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
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