MOV on iOS App shows QuickTime Logo At Beginning - ios

In my app I use, I loop a video over and over again. It will always show the QuickTime logo at the beginning of the video each time. I have checked, and there isn't anything like that in the video. Thoughts to how I can get rid of that?
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:#"warpspeed" withExtension:#"mov"];
UIView *patternView = [[UIView alloc] initWithFrame:self.view.bounds];
patternView.backgroundColor = [UIColor blackColor];
[self.moviePlayer2.backgroundView addSubview:patternView];
self.moviePlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.moviePlayer2 setControlStyle:MPMovieControlStyleDefault];
self.moviePlayer2.controlStyle = MPMovieControlStyleNone;
self.moviePlayer2.scalingMode = MPMovieScalingModeAspectFit;
self.moviePlayer2.movieSourceType = MPMovieSourceTypeFile;
[self.moviePlayer2 setAllowsAirPlay:YES];
self.moviePlayer2.view.frame = self.view.frame;

Related

Add AVPlayerLayer to UIViewController

Is it possible to display AVPlayerLayer inside a UIViewController which is later on displayed in UIView.
The sample code of what I'm trying to do:
...
UIView *parentView = reinterpret_cast<UIView *>(window->winId());
AVPlayer *_player;
AVURLAsset *_asset;
AVPlayerItem *_playerItem;
AVPlayerLayer *m_playerLayer;
_player = [[AVPlayer alloc] init];
NSURL *baseURL = [[NSURL alloc] initWithString: #"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
_asset = [AVURLAsset assetWithURL:baseURL];
_playerItem = [AVPlayerItem playerItemWithAsset: _asset];
[_player replaceCurrentItemWithPlayerItem:_playerItem];
m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
// works with AVPlayerViewController
// AVPlayerViewController *playerController = [[AVPlayerViewController alloc] init];
// playerController.player = _player;
UIViewController *viewController = [[UIViewController alloc] init];
[viewController.view.layer addSublayer:m_playerLayer];
viewController.view.frame = CGRectMake(this->x(), this->y(), this->width(), this->height());
[parentView addSubview:viewController.view];
[_player play];
...
It works if I try to add the player to AVPlayerViewController and then display it, but I would want to use only AVPlayerLayer since I don't need video controls as I'll implement the functionality separately.
You can use AVPlayerViewController with
avController.showsPlaybackControls = false;
Or simply add the layer
_player = [[AVPlayer alloc] init];
NSURL *baseURL = [[NSURL alloc] initWithString: #"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
_asset = [AVURLAsset assetWithURL:baseURL];
_playerItem = [AVPlayerItem playerItemWithAsset: _asset];
[_player replaceCurrentItemWithPlayerItem:_playerItem];
m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
m_playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:m_playerLayer ];
[_player play];
I subclassed UIView and added on the AVPlayerLayer via SH_Khans method
_player = [[AVPlayer alloc] init];
NSURL *baseURL = [[NSURL alloc] initWithString: #"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
_asset = [AVURLAsset assetWithURL:baseURL];
_playerItem = [AVPlayerItem playerItemWithAsset: _asset];
[_player replaceCurrentItemWithPlayerItem:_playerItem];
m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
m_playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:m_playerLayer ];
[_player play];
Then treat the subclassed UIView how you want. Couple of things though, if you resize the AVPlayerLayerUIView you have to resize the AVPlayerLayer as the system does not do that automatically.
Additionally remember to clip to bounds on the AVPlayerLayerUIView or it will not match your frame as you want.

How do I place a label over an AVPlayer playing a video?

How do I place a label over or "on top of" an AVPlayer playing a video? I have tried adjusting Z-position as suggested in another SO post but it is not working, the video player seems to be in the front of all the labels.
//this is my label
self.commentLabel.layer.masksToBounds = YES;
self.commentLabel.layer.cornerRadius = 15.0;
[self.commentLabel sizeToFit];
self.commentLabel.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/1.4);
self.commentLabel.layer.zPosition=100;
//this is my video player
self.playerViewController = [[AVPlayerViewController alloc] init];
NSString*str3=[self.FRIENDDATA stringByReplacingOccurrencesOfString:#" " withString:#"_"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://my.website.com/%#/%#.mp4", str3,self.RANDOMDATA]];
AVURLAsset *asset = [AVURLAsset assetWithURL: url];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];
AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem: item];
self.playerViewController.player = player;
[self.playerViewController.view setFrame:self.referenceImageView.frame];
self.playerViewController.view.layer.zPosition=0;
self.playerViewController.showsPlaybackControls = YES;
[self.view addSubview:self.playerViewController.view];
Have you tried adding the label subview onto the playerViewController ?
[self.playerViewController.view addSubview:self.commentLabel];
From the code I am unsure if commentLabel is not yet initialized or if it initialized somewhere else in the code or from a storyboard. It would be great to initialize the commentLabel on the playerViewController
Like this:
UILabel *commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/1.4, 100, 100)];
[self.playerViewController.view addSubview:commentLabel];
That should resolve your issue

Image doesn't show on top of a MPMoviePlayerController [duplicate]

I have a controller where I displays a video using MPMoviePlayerController. And I need to put an image over the video.
I am trying with the following code, but it doesn't show up. What I am missing?
// method to play the video
- (void)playVideoInLoopMode:(BOOL)loop {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"myvideo" ofType:#"m4v"]];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
mp.controlStyle = MPMovieControlStyleNone;
if (loop) {
mp.repeatMode = MPMovieRepeatModeOne;
}
mp.view.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height);
self.player = mp;
[self.view addSubview:self.player.view];
[self.player prepareToPlay];
[self.player play];
}
// method to add the image
- (void) addImageLayer {
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myimage"]];
image.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:image];
}
First I am running the video with the method: [self playVideoInLoopMode:YES] and after 5 seconds I am trying to put the image layer with the method [self addImageLayer];
In my AppDelegate.h I have this code in the didFinishLaunchingWithOptions:
MyViewController *myVC = [[MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
[self.window addSubview:myVC.view];
[self.window makeKeyAndVisible];
Try adding the image view to the mp.view and then u add the mp.view to the general view
for example if the image will be always the same u can add it in your starting code and delete the method to add the view...
// method to play the video
- (void)playVideoInLoopMode:(BOOL)loop
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"myvideo" ofType:#"m4v"]];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
mp.controlStyle = MPMovieControlStyleNone;
if (loop)
{
mp.repeatMode = MPMovieRepeatModeOne;
}
mp.view.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height);
self.player = mp;
[self.view addSubview:self.player.view];
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myimage.png"]];
image.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.player addSubview:image];
[self.player prepareToPlay];
[self.player play];
}

Run multiple video file in objective c

There are two video file.When I want to see these two video
1) Only the last video file can play,see in fullscreen mode and also minimise when done button clicked..but first video file can't .
2) After a few time the first video file also see in black screen
- (void)viewDidLoad
{
[super viewDidLoad];
MPMoviePlayerController *moviePlayer;
NSArray *filename=#[#"nissan1",#"nissan5"];
//n![enter image description here][1]issan1,nissan5 are mp4 file
NSURL *fileURL1 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[filename objectAtIndex:0] ofType:#"mp4"]];
moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:fileURL1];
[moviePlayer.view setFrame:CGRectMake(5, 50, 100,100)];
moviePlayer.shouldAutoplay = NO;
moviePlayer.repeatMode = MPMovieRepeatModeOne;
moviePlayer.initialPlaybackTime = -1.0;
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[moviePlayer prepareToPlay];
[self.view addSubview:moviePlayer.view];
/* second video file*/
NSURL *fileURL2 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[filename objectAtIndex:1] ofType:#"mp4"]];
moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:fileURL2];
[moviePlayer.view setFrame:CGRectMake(200, 50, 100,100)];
moviePlayer.shouldAutoplay = NO;
moviePlayer.repeatMode = MPMovieRepeatModeNone;
moviePlayer.initialPlaybackTime = -1.0;
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[moviePlayer prepareToPlay];
[self.view addSubview:moviePlayer.view];
}
You should try with two instances. As Cristik pointed out, ARC targets it for deallocation once the method ends and you are using same variable.
Since you asked for sample code, try this:
- (void)viewDidLoad
{
[super viewDidLoad];
MPMoviePlayerController *moviePlayer1;
MPMoviePlayerController *moviePlayer2;
//filename is a name array
NSURL *fileURL1 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[filename objectAtIndex:0] ofType:#"mp4"]];
moviePlayer1= [[MPMoviePlayerController alloc] initWithContentURL:fileURL1];
[moviePlayer1.view setFrame:CGRectMake(5, 50, 100,100)];
moviePlayer1.shouldAutoplay = NO;
moviePlayer1.repeatMode = MPMovieRepeatModeOne;
moviePlayer1.initialPlaybackTime = -1.0;
moviePlayer1.movieSourceType = MPMovieSourceTypeFile;
[moviePlayer1 prepareToPlay];
[self.view addSubview:moviePlayer1.view];
/* second video file*/
NSURL *fileURL2 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[filename objectAtIndex:1] ofType:#"mp4"]];
moviePlayer2= [[MPMoviePlayerController alloc] initWithContentURL:fileURL2];
[moviePlayer2.view setFrame:CGRectMake(200, 50, 100,100)];
moviePlayer2.shouldAutoplay = NO;
moviePlayer2.repeatMode = MPMovieRepeatModeNone;
moviePlayer2.initialPlaybackTime = -1.0;
moviePlayer2.movieSourceType = MPMovieSourceTypeFile;
[moviePlayer2 prepareToPlay];
[self.view addSubview:moviePlayer2.view];
}

What is the best way playing MOV file?

I have generated that MOV file from the screen shots of the UI and record the sound. Combined both video and audio and generate a MOV formatted movie.
I have seen quite a lot of MPMoviePlayerViewController sample but it just shows me black screen. I tried AVPlayer but I can't get it work.
I'm new to playing movie file in iOS, please help.
Here is my code:
NSString *fileNamePath = mVideo;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *oldappSettingsPath = [documentsDirectory stringByAppendingPathComponent:fileNamePath];
NSURL *path = [NSURL fileURLWithPath:oldappSettingsPath];
self.mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:path];
self.mPlayer.controlStyle = MPMovieControlStyleFullscreen;
self.mPlayer.fullscreen = YES;
self.mPlayer.scalingMode = MPMovieScalingModeFill;
[[self.mPlayer view] setFrame: CGRectMake(0, 0, 480, 320)];
[self.view addSubview:[self.mPlayer view]];
[self.mPlayer prepareToPlay];
[self.mPlayer play];
I have found the fixed to my MPMoviePlayerController :
NSURL *path = [NSURL fileURLWithPath:oldappSettingsPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:oldappSettingsPath]) {
NSLog(#"Exist");
self.mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:path];
self.mPlayer.movieSourceType = MPMovieSourceTypeFile;
self.mPlayer.controlStyle = MPMovieControlStyleFullscreen;
self.mPlayer.fullscreen = YES;
self.mPlayer.scalingMode = MPMovieScalingModeFill;
[[self.mPlayer view] setFrame: CGRectMake(0, 0, 480, 320)];
[self.view addSubview:[self.mPlayer view]];
[self.mPlayer prepareToPlay];
[self.mPlayer play];
} else {
NSLog(#"Don't Exist");
}
I added also:
self.mPlayer.movieSourceType = MPMovieSourceTypeFile;
in my case the player shows black screen since the file i played is not there, so i added a checking first if the file exist or not.

Resources