NSURL *url= [NSURL URLWithString:#"http://www.dailymotion.com/video/x109z02"];
MPMoviePlayerController *theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
theMoviPlayer.scalingMode = MPMovieScalingModeFill;
theMoviPlayer.view.frame = CGRectMake(0, 60, 320, 350);
[self.view addSubview:theMoviPlayer.view];
[self.theMoviPlayer play];
framework is also addded and imported in .h file but video is not playing in iphone (internet connection is also ok)
NSURL *url = [NSURL URLWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
Use the UIWebView , a very simple and easy way.
Related
I have a MPMoviePlayerViewController to play Movies in fullscreen. I checked the movies they play fine via Quicktime.
The Problem is, that using the MPMoviePlayerViewController (Simulator and device) the Movie doesn't start playing(it's a video that is stored locally on the iPad btw).
NSString *path = [[NSBundle mainBundle]pathForResource:resource ofType:#"mov"];
self.mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:path]];
[self.mpviewController.moviePlayer prepareToPlay];
self.mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.mpviewController.moviePlayer.controlStyle = [self presentModalViewController:self.mpviewController animated:YES];
NSLog(#"%d",self.mpviewController.moviePlayer.loadState);
[self.mpviewController.moviePlayer play];
Any Ideas what I am missing ?
tia
well, I dont know what it was. I ended up writing a new view controller with this code - that worked:
NSURL *url = [NSURL fileURLWithPath:self.urlPath];
self.playerController = [[MPMoviePlayerController alloc] initWithContentURL: url];
CGRect bounds = CGRectMake(0, 0, 1024, 748);
self.playerController.scalingMode = MPMovieScalingModeNone;
[self.playerController.view setFrame:bounds];
[self.view addSubview:self.playerController.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidExitFullscreenCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.playerController];
self.playerController.controlStyle = MPMovieControlStyleFullscreen;
[self.playerController setFullscreen:YES animated:YES];
[self.playerController play];
I want to play a video which is uploaded to the server from an iPad application, but when the screen loads it gives an error:
An AVPlayerItem cannot be associated with more than one instance of AVPlayer
I am using the following code:
-(void)playVideo{
NSURL *url = [NSURL URLWithString:#"http://celeritas.com.pk/emrapp/test.mp4"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mp];
[mp release];
NSLog(#"Successfully playing thanks");
}
-(void)playbackFinishedCallback:(NSNotification *)notification{
MPMoviePlayerController *movie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
[movie release];
}
http://celeritas.com.pk/emrapp/test.mp4 the URL seems to be wrong...
The requested URL /emrapp/test.mp4 was not found on this server.
Any way this will work
.h
MPMoviePlayerViewController * plyr;
NSURL * url;
#property (nonatomic,retain) MPMoviePlayerViewController *plyr;
#property (nonatomic,retain) NSURL *url;
.m
#synthesize plyr ;
#synthesize url;
url = [NSURL URLWithString:#"valid url"];
plyr = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
Url might be wrong double check that video url link is accessible, secondly do see your network firewall this might also cause problem.
The one tweak you can change instead of:
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
use:
mp.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
try this
create object of MPMoviePlayerViewController in .h like MPMoviePlayerViewController *mp;
#import<MediaPlayer/MediaPlayer.h>
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setUseApplicationAudioSession:NO];
[[mp moviePlayer] setShouldAutoplay:YES];
[[mp moviePlayer] setControlStyle:2];
[[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne];
[self presentMoviePlayerViewControllerAnimated:mp];
try this Code
-(IBAction)playMovie:(id)sender
{
NSURL *fileURL = [NSURL URLWithString:#"http://www.youtube.com/watch?v=3Qjh56woQMw"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotificationobject:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
I am am working on my app.which have requirement play video on iPhone by server. I have a video link http://www.cwtmedia.se/cwtvideo.mp4 . Can any body suggest me how i perform this on MPMoviePlayerController.I am using this code for that but its not working.
enter code here
NSURL *url = [NSURL fileURLWithPath:#"http://www.cwtmedia.se/cwtvideo.mp4"];
moviePlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer1.view];
moviePlayer1.view.frame = CGRectMake(0, 0, 320, 416);
moviePlayer1.fullscreen=YES;
[moviePlayer1 setFullscreen:NO animated:YES];
moviePlayer1.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer1 play];
by the way here's how i use mpmovieplayercontroller for streaming :
NSURL *url = [NSURL URLWithString:videoUrl];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleDefault];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
CGRect frame;
if(self.interfaceOrientation ==UIInterfaceOrientationPortrait)
frame = CGRectMake(20, 69, 280, 170);
else if(self.interfaceOrientation ==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation ==UIInterfaceOrientationLandscapeRight)
frame = CGRectMake(20, 61, 210, 170);
[moviePlayer.view setFrame:frame]; // player's frame must match parent's
[self.view addSubview: moviePlayer.view];
[self.view bringSubviewToFront:moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer prepareToPlay];
[moviePlayer play];
and then here's the delegate method :
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player respondsToSelector:#selector(setFullscreen:animated:)]){
//self.navigationController.navigationBarHidden = YES;
[player.view removeFromSuperview];
}
}
hope this will help you..
As far as I know you have 2 options:
1) First download the file and play it locally. Like this:
NSString *url = [[NSBundle mainBundle] pathForResource:#"cwtvideo" ofType:#"mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
2) Use the HTTP streaming protocol. As far as I know HTTP streaming is the only streaming protocol known by the MPMoviePlayerController.
Hope this helps.
Cheers!
This is the code segment i am using in my iOS Application to play the Streaming Video from the Server . But its not playing the video
-(IBAction)PlayTV:(id)sender{
MPMoviePlayerController *player2 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://87945.obj.myservmedia.net/quit1/mpegts.stream/playlist.m3u8"]];
player2.movieSourceType = MPMovieSourceTypeStreaming;
player2.view.frame = CGRectMake(25, 117, 270, 189);
player2.view.backgroundColor = [UIColor blackColor];
player2.view.hidden = NO;
[self.view addSubview:player2.view];
[player2 play];
}
NSURL *mediaURL = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
mp.view.frame = self.view.bounds;
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
I am running an intro movie in a MPMoviePlayerController and i've got a problem with the allocated memory not being released.
When the movie finishes, Instruments shows the memory being released.
However when i skip the movie by tapping on it the memory is not released.
Here are the important parts of my code:
- (void)applicationDidFinishLaunching:(UIApplication *)theApplication {
self.application = theApplication;
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"mymovie.mov" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[window addSubview:moviePlayer.view];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.frame = window.frame;
UIView *introFrontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
introFrontView.userInteractionEnabled = YES;
introFrontView.opaque = NO;
introTabRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(introTabFrom:)];
[introFrontView addGestureRecognizer:introTabRecognizer];
[moviePlayer.view addSubview:introFrontView];
[introFrontView release];
[introTabRecognizer release];
self.moviePlayerController = moviePlayer;
[moviePlayer release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(introFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[self.moviePlayerController play];
}
- (void)introTabFrom:(UITapGestureRecognizer*)recognizer{
[[NSNotificationCenter defaultCenter] postNotificationName:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
}
- (void) introFinished:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[self.moviePlayerController pause];
[self.moviePlayerController stop];
[self.moviePlayerController release];
...
}
Is there anything i forgot? To my understanding i'm posting the correct notification...
Any ideas?
You may want to register for MPMoviePlayerPlaybackStateDidChangeNotification, and look at the playbackState that is passed in.