- (void)viewDidLoad {
[super viewDidLoad];
NSURL *videoURL = [[NSBundle mainBundle]URLForResource:#"thoughtcastAnimate_v02" withExtension:#"mov"];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];
// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;
// Do any additional setup after loading the view.
}
This works fine with an mp4 file. But I need a .mov file to be played! This is for my application splash screen. I added the .mov file to the assets. Not sure what to do here.
I just needed to add my mov file to the Build Phases
Related
In AVPlayer default video forward slider and play button are not showing if AVPlayer is added to UIView
NSURL *videourl= [NSURL URLWithString:strUrl];
AVPlayer *player = [AVPlayer playerWithURL:videourl];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
playerViewController.view.frame = ViewAV.bounds;
AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = ViewAV.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//externalPlaybackVideoGravity
playerLayer.contentsGravity = AVLayerVideoGravityResizeAspect;
[ViewAV.layer addSublayer:playerLayer];
[ViewAV addSubview:playerViewController.view];
[playerViewController.player play];
Try setting showsPlaybackControls and requiresLinearPlayback to true,
playerViewController.showsPlaybackControls = YES;
playerViewController.requiresLinearPlayback = YES;
Currently, you didn't add playerViewController as child viewController so you will not be able to see anything. Add as below,
[self addChildViewController:playerViewController];
[self.view.layer addSublayer:playerLayer];
[self.view addSubview:playerViewController.view];
If I hit below url in browser, it plays video but my below code is not playing it on iPhone.
http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4"]];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
this is the screenshot of the iPhone.
MPMoviePlayerController is deprecated. You can use AVPlayer instead.
AVPlayer *player = [AVPlayer playerWithURL:"URL"];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
controller.player = player;
[player play];
You need to tell the MPMoviePlayerController that it needs to stream the video. Just add the following line:
moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
yes , you have to tell its streaming url as :
moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
then prepare to play
[moviePlayer prepareToPlay];
I am using my local router to play the video. I have configured my router and attached pendrive with my router. the pen drive have some video files. I am getting a URL (i.e http://192.168.0.1/user/root/Sample.mp4) from router . When i open this url on web browser, Video is playing perfectly fine but when try to play the same url using MPMoviePlayerViewController or AVPlayerViewController its not working.
One interesting thing i observed that if i open the same url on iphone browser its not playing.
Please help me or give me a idea why its not playing on mobile app.
moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[player prepareToPlay];
player.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:moviePlayerControll‌​er];
[moviePlayerController.moviePlayer play];
add player.movieSourceType = MPMovieSourceTypeStreaming; in your code
Edited
#property (strong, nonatomic ) MPMoviePlayerController*player;
NSURL *movieURL = [NSURL URLWithString:#"http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"];
self.player = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
[self.player prepareToPlay];
[self.player.view setFrame:CGRectMake(0, 0, 320, 320)];
[self presentMoviePlayerViewControllerAnimated:self.player];
self.player.fullscreen = YES;
self.player.controlStyle = MPMovieControlStyleDefault;
self.player.movieSourceType = MPMovieSourceTypeStreaming;
// player's frame must match parent's [self.view addSubview: self.movieController.view]; [self.movieController play];
[self.player play];
[self.view addSubview:self.player.view];
I had problem for playing video.I tried lot of ways but nothing helped.Then finally I went with below code.It works fine now.I use iOS 10.So I use AVPlayerViewController as MPMoviePlayerViewController is deprecated.
ViewController.h
#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) AVPlayerViewController *playerViewController;
- (IBAction)actionPlayVideo:(id)sender
#end
ViewController.m
#import "ViewController.h"
#interface ViewController (){
NSURL *vedioURL;
}
#end
#implementation ViewController
#synthesize playerViewController;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)actionPlayVideo:(id)sender
{
vedioURL = #"192.168.0.1/user/root/Sample.mp4";
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:vedioURL];
AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = playVideo;
playerViewController.player.volume = 0;
playerViewController.view.frame = self.view.bounds;
[self.view addSubview:playerViewController.view];
[playVideo play];
}
Please check with your iPhone,iPad or iPod
I am Using AVPlayerViewController here in portrait mode it looks fine but when i change the orientation to landscape mode the player gets too small it look like single tool bar. How can i fix the player size in both portrait mode and in landscape mode and it should be flexible when the device size also changes or can we fix it to the screen centre so the little size difference won't matter if played on bigger device size 6s Plus.
NSString *localfilepath=[NSString stringWithFormat:#"%#",[managedObject valueForKey:#"clip_path"]];
NSURL *url = [NSURL URLWithString:[localfilepath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = CGRectMake(10,80,controller.view.frame.size.height+(self.view.frame.size.width/1.6),self.view.frame.size.width/1.2);
controller.player = player;
controller.showsPlaybackControls = YES;
//player.closedCaptionDisplayEnabled = NO;
// [player pause];
[player play];
I am trying to play movies from a view controller. I am using the code below to do that:
VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:#"videoPlayerController"];
moviePlayer.view.frame = rect;
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[window.rootViewController presentViewController:moviePlayer animated:NO completion:nil];
[moviePlayer playMoviesForItems:items];
Normally it works fine. But sometimes, movie starts but I cannot see the video, just I can hear the sounds.
What is the best way to play video on top of everything?
NSString *path = [[NSBundle mainBundle] pathForResource:#"myVideo" ofType:#"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
Another solution would be to segue to another ViewController and dissmiss it when the movie ends.
You can also try using AVPlayer. In that case, you can play the video in your current view itself without having a separate overlay for the video.
Here's an example of playing multiple AVPlayers. You can modify the code to play a single video.