VLCKit Unable to play video in cocoa programming for objective-c? - 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"];

Related

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?

iOS 8.2 upgrade not show image in UIImageView, but only in app loaded through iTunes or TestFlight not Xcode

As weird as it sounds...
App loaded through test flight or iTunes does not show image on the screen, but it does when it is loaded through Xcode. I believe the UIImageView is there, and the UIImage is loaded.
App loaded through the Xcode works.
If the device is connected to the Xcode and debugging, device connected with USB cable. App works despite the load method...
Core data seems to works in all cases.
Any idea, somebody has seen something similar. I am quite lost.
Also if you have any tip on how to debug this on the device I will appreciate it.
The few code I think it is involve.
I am loading the UIImage from disk using
UIImage * previewImage = [UIImage imageWithContentsOfFile:path];
The image is located in Documents Directory fileName is the input
NSURL *documentsFolderURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *documentsFolderPath = [documentsFolderURL path];
if (![_documentsDirectory isEqualToString:documentsFolderPath]) [self generateLocaFolderPath];
NSString *returnedPath = [_documentsDirectory stringByAppendingPathComponent:fileName];
return returnedPath;
and setting the image in the imageView with
previewView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frameImageThumbnail.size.width, frameImageThumbnail.size.height)];
[previewView setImage:previewImage];
Everything else seems to work well...
My first question!!! Thanks for reading!
_ edit _
I had the strong believe now that the problem is not in the UIImage, I have use the same methods in other parts of the app and it is working fine.
But now I believe the problem is in the animation I perform to the UIView that contains the UIImageView.
[_view setFrame:frameImageThumbnail];
[_view setClipsToBounds:YES];
[_view setAutoresizesSubviews:YES];
[_image setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[_view addSubview:_image];
[UIView animateWithDuration:0.4
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^(void){
CGRect destination1Frame = _view.frame;
//... some complicated calculations with the rect ...
[_view setFrame:destination1Frame];
[UIView transitionFromView:_customView toView:_view duration:0 options: UIViewAnimationOptionShowHideTransitionViews completion:^(BOOL finisehdCompletion){
//stop showing video in _customView
}];
}];
I am using NSAutolayout in the storyboard. Though my application only allows one landscape orientation. No idea if all this meshing up with the frames it is making.
dizzy to the poor auto layout guy...
Make sure you have / your image is set in Copy Bundle Resources. You can check if your image path is valid also. But I think the image is not set to copy at Build Phases.
I had the same problem.. Haven't find a correct solution.
But I deleted the image(check if it's deleted in ur Bundle resources), then put the image again, with ANOTHER name.
It worked for me. It's a temporary solution, idk if it's an apple bug or what.
Ok After more than 20 ipa files build and installed in my devices. In all this process to get rid of the problem I removed the _view from the storyboard, and initiallize the view programmatically. I remember that _view was originally set to (weak, nonatomic) property because was made with the storyboard, this super nice ctrl+.
That was I change I made, weak to Strong, and works now.
I don't know why it didn't work only when the program was install through iTunes with the ipa file or through the test flight app. That is still a mystery to me.

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 not playing any video content [due to ARC and memory management]

I am trying to get a video playing in an iOS applocation, using MPMoviePlayerController to append a movie-view to an existing view when a user pushes a button.
The view appears as a black box on the right position and everything, but nothing happens.
I am expecting the movie to start playing, but nothing happens and no hints from the application on why.
Can anyone see where this goes wrong?
-(IBAction) playButtonClicked:(id)sender
{
NSString* path = [[NSBundle mainBundle] pathForResource:#"sample_mpeg4" ofType:#"mp4"];
NSLog(#"Using videoPath %#", path);
NSURL* url = [NSURL fileURLWithPath:path];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:player.view];
player.view.frame = CGRectMake(10, 10, 300, 220);
[player play];
}
The movie exists and logs the correct path, but still no movie playing.
2012-07-06 11:51:13.492 experiments[84702:12203] Using videoPath /Users/marius/Library/Application Support/iPhone Simulator/5.1/Applications/9799C851-8D2B-4CFE-8CFA-A4C4C954787F/experiments.app/sample_mpeg4.mp4
From what I have read and understood this should be working.
Any hints or suggestions on what to try?
I moved the movie to a HTTP-server (fg.mp4) and are tailing the access-logs.
When clicking the play-button the usual black window appears.
Serverside i find two new entries in the log:
168.122.x.x - - [06/Jul/2012:22:42:33 +0200] "GET /fg.mp4 HTTP/1.1" 304 192 "-" "AppleCoreMedia/1.0.0.9B176 (iPhone Simulator; U; CPU OS 5_1 like Mac OS X; en_us)"
168.122.x.x - - [06/Jul/2012:22:42:33 +0200] "GET /fg.mp4 HTTP/1.1" 206 33304 "-" "AppleCoreMedia/1.0.0.9B176 (iPhone Simulator; U; CPU OS 5_1 like Mac OS X; en_us)"
So the phone gets parts of the movie content, and -apparently- prepares to get the rest when needed.
Is there some obvious parameter for the MPMoviePlayerController I'm missing?
UPDATE: Solution and working code
The problem is caused by ARC and the fact that no reference to the MPMoviePlayerController were kept after calling the method setting up the controller.
The solution: Adding a class-variable to the class and use this to keep a reference to the controller for the lifetime of the movie.
So early in the class declaration (outside any message/function-definitions):
MPMoviePlayerController* mpController;
And the abeformentioned playButtonClicked uses this variable to keep track of the controller:
NSString* path = [[NSBundle mainBundle] pathForResource:#"sample_mpeg4" ofType:#"mp4"];
NSURL* url = [NSURL fileURLWithPath:path];
mpController = [[MPMoviePlayerController alloc] initWithContentURL:url];
mpController.view.frame = CGRectMake(10, 10, 300, 220);
[self.view addSubview:mpController.view];
[mpController play];
As with my answer to MPMoviePlayerController playback terminates before video finishes, this looks to be a memory management (instance lifetime) issue. Assuming you are compiling with ARC, the player variable is released when your playButtonClicked: method returns. At that point the MPMoviePlayerController instance takes its bat and ball, and goes home.
Try assigning the MPMoviePlayerController instance to a strong instance variable or property.
Nothing seems obviously out of place to me. Here are some debugging tips to help narrow down the problem:
try using a URL to an mp4 file served over http---that should tell you whether it's a UI problem or an asset problem.
try inspecting the url for properties such as the file length and confirm that it exactly matches what you expect.

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.