MPMoviePlayerController cannot play some 3gp format video - objective-c

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.

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"];

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

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?

Play a sound with silent mode iOS 5 and iOS 6

I'm trying to test to play a song in with silence mode activate.
I have this code which I picked up from the answers in this web:
if(CFStringGetLength(state) == 0) {
//SILENT
NSLog(#"Silent switch is on");
//create vibrate
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//this 2 line below use to play audio even in silent/vibrator mode too
UInt32 audioCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty( kAudioSessionProperty_AudioCategory, sizeof(UInt32), &audioCategory);
NSError *error;
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL URLWithString:soundPath] error:&error];
[player play];
NSLog(#"error %#",error);
}
else {
//NOT SILENT
NSLog(#"Silent switch is off");
AudioServicesPlaySystemSound(finishedSound);
}
I'm testing in a iPod touch 4 generation ios 6 the sound sounds when the app is in background and foreground (with volume to a minimum).
But with iPad one with iOS 5.1.1 it doesn't sound none of two situations.
The sound sounds with the silence mode off in both devices.
Do you know what can I change to achieve that the app sounds in both situations ?

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.

Youtube embedded in UIWebView causes crash on iPad when entering full screen

I'm trying to embed a Youtube video using a mixture of this technique, and this Youtube SDK blog post in a universal app. The iPhone version, using the same code, works fine.
On the iPad the video does embed, and it plays fine in it's embedded form, but as soon as you tap the full screen button the app crashes (buttons do not respond, the device does not rotate). The music from the Youtube video keeps playing.
There is no error message logged but the app does register as 'Paused' or hung in xCode. Every time it crashes com.apple.libdispatch-manager is on thread 2. Ask me questions and I'll give you more information about the error, but I'm not sure where to start.
I have tried:
changing the size of the UIWebView frame
the UIWebView is in a UIScrollView, but if I take it out of the scrollview and add it to the view the problem is identical.
changing the video
changing the html that I use in the UIWebView from this to this, with no result
changing the format of the youtube link from ?v=uniqueID to /v/uniqueID
checking the presenting view is the rootviewcontroller (it is, but the video is embedded in a modal, which is not the rootviewcontroller).
I am building for iOS 5.1, this doesn't happen if running on iOS6.
The View that the video is embedded in is modal, both on the phone and the iPad. There's no hackery or unusual things happening in the app.
There seems to be talk of Evernote's app having a similar problem, but I don't know if it is related or not.
For your reference, here is the YouTubeView subclass (which subclasses UIWebView):
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
{
if (self = [super init])
{
// Create webview with requested frame size
self = [[YouTubeView alloc] initWithFrame:frame];
// HTML to embed YouTube video
// NSString *youTubeVideoHTML = #"<html><head>
// <body style=\"margin:0\">
// <embed id=\"yt\" src=\"%#\"
// type=\"application/x-shockwave-flash\"
// width=\"%0.0f\" height=\"%0.0f\">
// </embed>
// </body>
// </html>";
NSString *youTubeVideoHTML = #"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = %0.0f\"/></head><body style=\"background:#FFF;margin-top:0px;margin-left:0px\"><div><object width=\"%0.0f\" height=\"%0.0f\"><param name=\"movie\" value=\"%#\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%#\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"%0.0f\" height=\"%0.0f\"></embed></object></div></body></html>";
// Populate HTML with the URL and requested frame size
// NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];
NSLog(#"html:\n %#", youTubeVideoHTML);
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, frame.size.width, frame.size.width, frame.size.height, urlString, urlString, frame.size.width, frame.size.height];
NSLog(#"html:\n %#", html);
// Load the html into the webview
[self loadHTMLString:html baseURL:nil];
}
return self;
}
Modal view on iOS 5.0 and iOS 5.1 is the problem that causes crash on full screen video, AFAIK. They just changed hierarchy of views in that version of iOS (parentViewController and presentingViewController) and that is the aftermath. I asked about it long time ago here and one more same question is here and still no one knows what to do.
First of all, they fixed it in 6.0, I guess, that's good.
For 5.1 we changed design a little and avoided modal view. Do it, if it is possible in your situation.