Play video through URL link - objective-c

I'm trying to play a youtube video through my app to test for videos that will need linked later (no videos to link yet). I'm trying everything from a UIImageView to UIWebView using MPMoviePlayer. It starts the player, then stops seconds later with the following in the log:
_itemFailedToPlayToEnd:
{
kind = 1;
new = 2;
old = 0;
}
_itemFailedToPlayToEnd:(null)
I'm not sure what's going wrong as I've not that much experience with streaming videos into my apps. Thanks for the help.
-(void)playMovie:(id)sender
{
UIWebView *video1 = [UIWebView new];
video1.frame = CGRectMake(100, 100, 60, 60);
NSURL *url = [NSURL URLWithString:#"https://www.youtube.com/watch?v=w9bBQRWkV8M"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(movieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mp];
[self.view addSubview:self.player.view];
[self.player setFullscreen:YES];
self.player.shouldAutoplay = YES;
[self.player prepareToPlay];
}

Related

iOS 7 Video not playing MPMoviePlayerController

This code is working perfect in iOS 8 . but unable to play video in iOS7.The player shows up but plays nothing.Thanks
NSString *url = #"http://.../playlist.m3u8";
NSURL *streamURL = [NSURL URLWithString:url];
self.streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
self.streamPlayer.controlStyle= MPMovieControlStyleFullscreen;
self.streamPlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.streamPlayer.shouldAutoplay = YES;
[self.view addSubview:self.streamPlayer.view];
[self.streamPlayer prepareToPlay];
[self.streamPlayer play];
From the documentation:
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
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];
Try to set the frame of your video player.

MPMoviePlayerController error _itemFailedToPlayToEnd while playing RTMP video link iOS 7

I am trying to play a video like:
- (void) playMovie {
NSURL *url = [NSURL URLWithString:
#"rtmp://122.129.75.174:61935/live/peghamtvX007"];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc]
initWithContentURL:url];
self.videoController = controller; //Super important
controller.view.frame = self.view.bounds; //Set the size
[self.view addSubview:controller.view]; //Show the view
[controller play]; //Start playing
}
But it failed to play. Here is error:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
Can i play rtmp link in WebView using MPMoviePlayerController? and also help me out in this error.

play video inside frame iOS (and center it)

I don't want to play a video in fullscreen, is it possible to play a video inside a view?
Here is my code. It does create a frame and plays the video inside it. The problem is that I don't know how to center on screen the frame (it appears on the right side of the screen)
Screenshot
NSBundle *bundle = [NSBundle mainBundle];
NSURL *url = [NSURL fileURLWithPath:[bundle pathForResource:#"movie" ofType:#"mov"]];
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
_moviePlayer.view.frame = CGRectMake(184, 200, 400, 300);
[self.view addSubview:_moviePlayer.view];
_moviePlayer.shouldAutoplay = YES;
replace a line with given below will fix your issue.
_moviePlayer.view.center = self.view.center;

Can not play video from URL in iPhone app?

I'm having a problem playing the video from URL-based. This is my code:
-(void)clickplay
{
NSURL *fileURL = [NSURL URLWithString:#"http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc]initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
It compiles successfully and the player did pop out but it just keeps loading forever... I have tried changing the URL several times to no effect. Can anyone please help me to solve this problem?
You'll need to retain a reference to the moviePlayerController. It's getting released and preventing any delegated messages from being invoked. Probably the easiest place to put it is in the class that contains the - (void)clickplay implementation. That is, add a new instance variable called moviePlayerController and assign it the newly created MPMoviePlayerController object in clickplay.
videoURL=[NSURL URLWithString:URL]];
videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
videoPlayer.view.frame = CGRectMake(0,0, 320, 480);
[videoPlayer prepareToPlay];
[self.view addSubview:videoPlayer.view];
[videoPlayer play];
videoPlayer.movieControlMode = MPMovieControlModeHidden;
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:videoPlayer];
/* configuring notification*/
- (void)moviePlayBackComplete:(NSNotification *)notification
{
[videoPlayer stop];
}
This my answer in regards with playing .3gp file with iPhone .....I have successfully played .3gp file with iphone sdk with using MpMoviePlayerController and my answer link is:
Link: https://stackoverflow.com/a/13088808/1092219
hope you will got help from my answer.........!! :))))))

How can I know when video play?

I have video in my project. I play it with MPMoviePlayerController but app will take time to load for a sec. Now I want to lunch another func. when video start to play. How can I know when video already load and start play and How to call another func. when it play ???
Could U guide me please ?
here is some simple code
-(IBAction)testVideoLongPress:(id)sender
{
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"video1" ofType:#"MOV"];
movie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
movie.view.backgroundColor = [UIColor blackColor];
movie.controlStyle = MPMovieControlStyleDefault;
movie.shouldAutoplay = YES;
movie.view.frame = CGRectMake(0, 50, 720, 1280);
[self.view addSubview:movie.view];
[movie play];
}
-(void)wannalunchthismethod
{
....
}
Look at the MPMoviePlayerLoadStateDidChangeNotification notification of MPMoviePlayerController and you'll be able to catch your movie player state changing to "play".