I am playing a m4v video in my app. It is playing fine but i just want to load the video without playing it. Just the preview.
I am using following code.
-(void)test
{
self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:#"YOUR_PATH"]];
//[self.player prepareToPlay];
[self.player setControlStyle:MPMovieControlStyleDefault];
[self.player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: self.player.view];
}
But If i am uncommenting [self.player prepareToPlay];, It is starting to play.
If I comment [self.player prepareToPlay];, video is not loading.
try this
-(void)test
{
self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:#"YOUR_PATH"]];
[self.player prepareToPlay];
[self.player play];
[self performSelector:#selector(pausePlayer) withObject:nil afterDelay:0.1];
[self.player setControlStyle:MPMovieControlStyleDefault];
[self.player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: self.player.view];
}
-(void)pausePlayer
{
if (self.player)
{
[self.player pause];
}
}
Related
- (void)viewDidLoad
{
[super viewDidLoad];
VLCVideoView *videoView = [[VLCVideoView alloc] initWithFrame:[[window contentView] bounds]];
[[window contentView] addSubview:videoView];
[videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
// Init the player object
VLCMediaPlayer *player = [[VLCMediaPlayer alloc] initWithVideoView:videoView];
[player setMedia:[VLCMedia mediaWithPath:#"rtmp://192.168.100.15:1935/vod"]];
[player play];
}
I want to play RTMP URL in VLCPlayer, but it's not working. I have tried many SDK's but have not got the solution yet.
I am playing a video from Url, It is playing but very slow. I am using my mobile data.
Her is the code I play the video:
self.avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:_selectedVideo.videoLink]];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
videoLayer.frame = self.view.bounds;
[self.view.layer addSublayer:videoLayer];
[self.avPlayer play];
It is really slow and takes long time to start. Is there any way to make it faster?
Thanks
You can try mpmovieplayer to play video.
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame
[myView addSubview: player.view];
// ...
[player play];
I have a problem while playing a video in full screen mode using MPMoviePlayerViewController (works perfectly in normal mode).
CODE:
if (PlayV) {
self.previewView.hidden=NO;
self.videoController =[[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
[self.videoController.view setFrame:self.previewView .frame];
self.videoController.view.center=self.playBtn.center;
[self.previewView addSubview:self.videoController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.videoController];
self.videoController.scalingMode = MPMovieScalingModeAspectFit;
self.videoController.controlStyle = MPMovieControlStyleNone;
[self.videoController play];
}
I got the solution. Add this line of code in playBtnAction method:
- (IBAction)playBtnAction:(id)sender {
[self.videoController setFullscreen:YES animated:YES];
}
and then add this line of code in your videoPlayBackDidFinish.
MPMoviePlayerController *player=[notification object];
if ([player respondsToSelector:#selector(setFullscreen:animated:)]) {
[player.view removeFromSuperview];
}
This code will check if the video is in fullscreen mode and bring it back to normal mode.
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:imagepath]]; //moviePlayer declared in .h and set URL
moviePlayer.view.frame = CGRectMake(364, 89, 660, 668); //set custom frame
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view]; //add to view
[moviePlayer setFullscreen:NO animated:YES];
This may help you.
I'm trying to use an MPMoviePlayerController on iOS to play back an audio stream over HTTP.
I've imported MediaPlayer.framework and used the code from MPMoviePlayerController's documentation, but I get no sound.
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://shoutmedia.abc.net.au:10326"]];
[player prepareToPlay];
[player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: player.view];
[player play];
I've also tried adding player.movieSourceType = MPMovieSourceTypeStreaming; but didn't work neither.
Any thoughts?
I am developing an iPad app where I am playing the videos stored within the app itself. I am representing the list of videos in a table view. When I select a row, the video
corresponding to that row plays. But while performing this, sometimes screen goes black , no video is visible but only audio is playing.
I am aware that making the video play in fullscreen mode or using the MPMoviePlayerViewController eliminates this problem. But my requirement is that I don't want to play the movie in fullscreen initially. Please guide me on how this can be achieved.
-(void)playMovie {
MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePalyer = movieController;
[movieController release];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object: self.moviePalyer];
self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313);
self.moviePalyer.view.backgroundColor = [UIColor clearColor];
[self.moviePalyer prepareToPlay];
[self.view addSubview: self.moviePalyer.view];
[self.moviePalyer play];
}
-(void)moviePalyerDidFinish:(NSNotification*)notification
{
[moviePalyer.view removeFromSuperview];
[moviePalyer stop];
moviePalyer.initialPlaybackTime = -1.0;
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePalyer];
[moviePalyer release];
moviePalyer = nil;
}
NOTE: This is on ipad simulator
I have solved the issue. Previously I was creating the MPMoviePlayerController for each of the row selection, and releasing it in the moviedidfinish notification method .But now, instead of creating movieplayercontroller for every row selection, I am reusing the MPMoviePlayerControler object which has been already created.
Following is the Code snippet:
-(void)playMovie
{
if(self.moviePalyer == nil)
{
MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.moviePalyer = movieController;
[movieController release];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePalyer];
self.moviePalyer.repeatMode = MPMovieRepeatModeOne;
self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313);
self.moviePalyer.view.backgroundColor = [UIColor clearColor];
}
else
{
[self.moviePalyer setContentURL:url];
[self stopMovie];
}
[self.view addSubview: self.moviePalyer.view];
[self.moviePalyer play];
}
-(void)stopMovie
{
[self.moviePalyer.view removeFromSuperview];
[self.moviePalyer stop];
self.moviePalyer.initialPlaybackTime = -1.0;
}
I am releasing the moviePlayer object in the dealloc method.
Hope this helps who is having the same issue.