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.
Related
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.
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];
}
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.........!! :))))))
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".
I got the thumbnail Image by passing the video url to the MPMoviePlayerController and I am playing the video by loading the Url string into the webview How can I set the Thumbnailimage as a thumnailwhen playing the video in webview at present I am getting white screen with play button.
My code is:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:newURL];
if (moviePlayer)
{
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayer setFullscreen:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleDurationAvailableNotification:)
name:MPMovieDurationAvailableNotification
object:moviePlayer];
moviePlayer.useApplicationAudioSession = NO;
UIImage *image = [moviePlayer thumbnailImageAtTime:(NSTimeInterval)1.0 timeOption: MPMovieTimeOptionNearestKeyFrame];
NSData *imgData = UIImagePNGRepresentation(image);
printf("\n length of ThumbnailImage Data...%d",[imgData length]);
// May help to reduce latency
//[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
///moviePlayer.view.frame = CGRectMake(184, 200, 400, 300);
//[self.view addSubview:moviePlayer.view];
//[moviePlayer play];
}
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
printf("\n Inside didSelect method....!!");
masterAisleItemListIndexArray = (NSMutableArray*)[ [masterAisleItemListDictionary allKeys] sortedArrayUsingSelector:#selector(compare:)];
NSString* sectionName = [masterAisleItemListIndexArray objectAtIndex:indexPath.section];
NSMutableArray* aisleItemsArray = [masterAisleItemListDictionary valueForKey:sectionName];
CustomerDetails *custObj = [aisleItemsArray objectAtIndex:indexPath.row];
//CustomerDetails *custObj = [videosList objectAtIndex:indexPath.row];
printf("\n audiofile = %s",[custObj.audioFile UTF8String]);
//NSURL *URL = [NSURL URLWithString:custObj.audioFile];
//printf("URL====%s",[URL UTF8String]);
webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 440)];
[myView addSubview:webView];
webView.backgroundColor = [UIColor blueColor];
[webView loadHTMLString:[self getVideo:custObj.audioFile] baseURL:[NSURL URLWithString:#"http:bluepal.com"]];
webView.delegate = self;
self.view = myView;
//[self downloadOutstandingFileSounds:custObj.audioFile];
}
-(NSString *)getVideo:(NSString *)aString
{
NSString *htmlString = #"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 94\"/></head><body style=\"background:#000;margin-top:0px;margin-left:0px\"><div><object width=\"90\" height=\"70\"><embed src=\"";
htmlString = [htmlString stringByAppendingString:aString];
htmlString = [htmlString stringByAppendingString:#"\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"400\"></embed></object></div></body></html>"];
printf("\n htmlString.......%s",[htmlString UTF8String]);
return htmlString;
}
Guys please give me suggestions to get out of this.
Hope I wil get quick response from your side.
Thanks all,
Lakshmi.