Video stucks/delayed while getting start using AVPlayer, in iPad pro only - objective-c

Am using AVPlayer to play video. Video playing without any problem except iPad Pro. In iPad pro its getting stuck or delayed to start.
avPlayerViewController = [[AVPlayerViewController alloc]init];
avPlayerItem = [[AVPlayerItem alloc]initWithURL:fileURL];
player = [[AVPlayer alloc]initWithPlayerItem:avPlayerItem];
avPlayerViewController.player = player;
[avPlayerViewController.view setFrame:CGRectMake(0, 0, biManager.screenSize.width, biManager.screenSize.height)];
[self.view addSubview:avPlayerViewController.view];
avPlayerViewController.showsPlaybackControls = false ;
[player play];

I think the initWithURL is a sync call and may stop your UI. I went around it in my code by saving the video to a temp file and start the play only when the file was downloaded. Alternatively, you can try loadValuesAsynchronouslyForKeys:completionHandler: as suggested in this SO post. Also, there should be a way to stream videos with buffering. May be with third party's API like AFNetworking?

Related

VLCKit Unable to play video in cocoa programming for objective-c?

I had tried to play video using vlckit for mac os x,
using below code but , i am unable to see video, after compiling i am having black screen but no video is playing.
here a.mp4 is my video inside main bundle , i had cheacked that videos path is correct.
let me know what is the issue why i am not able to see video on screen.
// Set up a videoView by hand. You can also do that in the nib file
videoView = [[VLCVideoView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)];
[self.view addSubview:videoView];
[videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
// Init the player object
player = [[VLCMediaPlayer alloc] initWithVideoView:videoView];
[player setMedia:[VLCMedia mediaWithPath:#"/Users/gurpalrajput/Desktop/demoVlc Player/demoVlc Player/a.mp4"]];
[player play];
That path looks wrong; for a resource inside a macOS application I would expect something like /path/to/Application.app/Contents/Resources/a.mp4. You're not on iOS anymore... ;)
Generally you want to resolve paths to resources inside the application bundle programmatically; for the movie that would be:
NSString* path = [NSBundle.mainBundle pathForResource:#"a" ofType:#"mp4"];

Playing video with notification

I am using the following to play a video named intro
- (IBAction)PlayIntro:(id)sender {
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"m4v"];
introplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]];
[self presentMoviePlayerViewControllerAnimated:introplayer];
}
I am having trouble setting up a notification so that once the video is finished playing the following would take place [self performSegueWithIdentifier:#"IntroS" sender:sender]; any help would be appreciated.
You should set up KVO for your MPMoviePlayerController. When the state of the movie changes, this fires giving you a chance to compare total playback time with the current playback time.
Given your snippet of code, this line will give you the current playback value:
NSLog(#"Movie player state: %g", introplayer.currentPlaybackTime);
I provided a brief overview on how KVO works with an example unrelated to video playback.
Though the topic is unrelated to video, it works just the same regardless of what variable you're watching using KVO.

video not playing ios 6

I am trying to play videos from url which my web service returns using MPMoviePlayerViewController. A sample url returned is:
http://view.vzaar.com/1128188/player
Which i pass to MPMoviePlayerViewController. Do you think this url is compatible to be played?
I looked at the source of that page, and it's an html page. I did find a html5 source url. Try:
http://view.vzaar.com/1128188/video
Yes, with above url. I just tried it in xcode and I got it to work.
NSURL *url = [[NSURL alloc] initWithString:#"http://view.vzaar.com/1128188/video"];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.moviePlayer prepareToPlay];
[self.moviePlayer.view setFrame:self.view.bounds]; // player's frame must match parent's
[self.view addSubview: self.moviePlayer.view];
[self.moviePlayer play];
No. It can't be played because it's an HTML page with a flash player embedded. Change your web service to return the video directly, possibly in a different URL.

MPMoviePlayerController cannot play some 3gp format video

I use MPMoviePlayerViewController to play a video with format 3gp. some video can played,but others cannot be played. MPMoviePlayerViewController will loading and end immediately,just like the video is 0 second duration.
i thought there must be sty wrong with the video. but i use the iphone's video player inside the album, it can play the video!
So i think maybe MPMoviePlayerViewController is not powerful.and i wanna try to use avfoundation framework avplayer to play video. add a sublayer into my content view. failed..
that drive me crazy! does anyone met the some problem?
here is my code
-(void) playMovieWithSDK: (NSURL*) movieUrl
{
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
MPMoviePlayerViewController *mSdk4Player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
mSdk4Player.navigationController.navigationBar.tag = 1000;
if (mSdk4Player) {
[self presentMoviePlayerViewControllerAnimated:mSdk4Player];
mSdk4Player.moviePlayer.scalingMode= MPMovieScalingModeAspectFit;
mSdk4Player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
mSdk4Player.moviePlayer.shouldAutoplay = YES;
[mSdk4Player release];
[[NSNotificationCenter defaultCenter]addObserver: self
selector: #selector(movieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: mSdk4Player.moviePlayer];
}
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) { // sdk 3.0 播放器
MPMoviePlayerController* mSdk3player = [[MPMoviePlayerController alloc] initWithContentURL: movieUrl];
mSdk3player.scalingMode = MPMovieScalingModeAspectFit;
[[NSNotificationCenter defaultCenter]addObserver: self
selector: #selector(movieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: mSdk3player];
[mSdk3player play];
}
}
The video you are trying to play might not be compatible with the basic Codecs supported by MPMoviePlayerController.
According to the documentation:
This class plays any movie or audio file supported in iOS. This includes both streamed content and fixed-length files. For movie files, this typically means files with the extensions .mov, .mp4, .mpv, and .3gp and using one of the following compression standards:
H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps.
(The Baseline profile does not support B frames.)
MPEG-4 Part 2 video (Simple Profile)
If you use this class to play audio files, it displays a white screen with a QuickTime logo while the audio plays. For audio files, this class supports AAC-LC audio at up to 48 kHz, and MP3 (MPEG-1 Audio Layer 3) up to 48 kHz, stereo audio.

Movie player has wrong activation state (1)

Hi! I am capturing the thumbnail image of video from video url. And I am using following code to capture the thumbnail
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:movieURL];
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayer setFullscreen:YES];
moviePlayer.useApplicationAudioSession = NO;
UIImage *image = [moviePlayer thumbnailImageAtTime:(NSTimeInterval)1.0 timeOption: MPMovieTimeOptionNearestKeyFrame];
I am using threading for this. I am getting the following error:
Movie player has wrong activation state (1)
Can anybody help me?
When you are initing the movie player, you already have one. There can be only one MPMoviePlayerController. You are probably doing this in a loop. You need to set your last one to nil or keep reusing the same one over and over.