Cocoa touch SDK 3.2 - How to play video [duplicate] - ipad

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Using MPMoviePlayerViewController in SDK 3.2 for iPad
How do I play video on SDK 3.2 (iPad)?
Read many questions here but they talked mostly for iPhone.
For example, the MoviePlayer example here http://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/Introduction/Intro.html
That works on 3.1.3 but when I run it on 3.2, it doesn't work.
So basically I'm able to play a video on 3.1.3 using this code but the same code won't run on 3.2
NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Movie.mp4"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
moviePlayer.movieControlMode = MPMovieControlModeDefault;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer play];
Thanks,
Tee

MPMoviePlayerController doesn't work on the iPad anymore - only audio is played. You have to use MPMoviePlayerViewController to get the correct functionality
Using MPMoviePlayerViewController in SDK 3.2 for iPad
Thanks for the update Apple :(

I got it to work. Here is how:
NSURL* videoURL = [NSURL URLWithString:url];
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
Thanks,
Tee

Related

Play facebook videos in ios application

I want to embed Facebook videos in my app. I am getting video links from a webservice.
For example:
"video_url": "https://www.facebook.com/urdutimes.ca/videos/520665921438799/"
Is it possible to embed this video in native iOS app using Objective-C?
Thanks in advance
Try this one:
NSURL *url = [NSURL URLWithString:#"https://www.facebook.com/urdutimes.ca/videos/520665921438799/"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mp];

How to loop mp4 file in UIWebView

I would like to loop a mp4 file in UIWebView.
e.g.
If you go to this link (http://techslides.com/demos/sample-videos/small.mp4) to open UIWebView, you won't be able to play it in loop. But I would like to watch this mp4 video for loop and loop again.
Please give me any tips to overcome!
Cheers,
You can simply use MPMoviePlayerController with setRepeatMode:MPMovieRepeatModeOne.
This should allow seamless looping of any video, and it's simple to implement.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Your Cool Video File" ofType:#"mp4"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[playerController.moviePlayer play];
Important to remember to subscribe to the end playback notification like so:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
Start playback manually in moviePlayBackDidFinished method

How to play video player one after another in ios?

i want to play video in ios one after another..I have two video files .m3u8 format. if video one completed then video two start automatically.. after video two complete then again video one should played automatically. and again video two should start automatically. how can i do this thing….I am using Mediaplayer framework. plz give me any idea…..Thanks in advance.
-(void)viewDidLoad
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"buyTutorial" ofType:#“m3u8”];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
[self setController:moviePlayerController];
}
You should be able to use this notification:
https://developer.apple.com/LIBRARY/IOS/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html#//apple_ref/c/data/MPMoviePlayerPlaybackDidFinishNotification
And then look for this constant PlaybackEnded:
https://developer.apple.com/LIBRARY/IOS/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html#//apple_ref/c/tdef/MPMovieFinishReason
Then just start the next movie in your playback queue.
Here's some examples on how to register to the notification:
MPMoviePlayerPlaybackDidFinishNotification being called again in iPhone 4.3 simulator when setting contentURL

MPMoviePlayerController doesn't play video

I'm using this code to try and play a video. However the video is never played, the call back is never made to say it's finished. I can't see anything that I'm missing or have where it shouldn't be. I've checked the path and that's fine. The video playback view does appear. It just doesn't play at that point.
Any suggestions?
NSURL *movieURL = [[NSBundle mainBundle] URLForResource:#"IntroMovie" withExtension:#"mov"];
NSLog(#"%#", movieURL);
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[moviePlayerController prepareToPlay];
[moviePlayerController.view setFrame:self.view.bounds];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
The problem lies within the fact, that your moviePlayerController is being cleaned up due to ARC.
Try if it helps to introduce a strong property for the MPMoviePlayerController.

iPhone/iPad Downloading and Playing Simultaneously

I want to Download and Streaming and Downloading the video simulteniouslly by App.
There video are heavy so Converted into m4u8 format and using the VOD Live streaming cocept to play them in MPMoviePlayer.
How to download there live streaming Video simulteniouslly with palying .
Can you suggest me.
FOllowing are the code to play the movie, Hope this is useful..
NSURL *fileURL = [NSURL URLWithString:#"<Video URL>"];
[self playMovie:fileURL];
-(IBAction)playMovie:(NSString *) theURL
{
NSURL *fileURL = [NSURL fileURLWithPath:theURL];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.useApplicationAudioSession = NO;
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
To Make the Video capable of streaming
Video should be of .mp4 format.
All videos should be converted using the Miro Video Converter in Mac (Or similar converters) and make it compatible to play in iPhone, iPad and Android devices.
Converted videos will play in mobile devices. However, the video will play only after the full video is downloaded from the server.
To make the video streaming, the video's metadata has to be moved to the beginning of the video. To achieve this, we have to use a tool called Medadata mover to encode the video.
Then the final video is compatible of streaming and able to play in all mobile devices.
Then the video have to be FTP'ed to the desired web hosting. for example demo.com/videos/test.mp4.
Then the video can be configured in iPhone or android app and can be streamed.
See More for Apple Live Streaming
HTTP LIve Streaming

Resources