I am sure I am just missing something stupid but I have been stuck on this all day. Any help would be appreciated. I was trying to embed video in an ipad app. I am using xcode 4.2.5. I am following a tutorial which I found here: embeded ipad video
I have followed the instructions exactly as far as I can tell. I have started over several times. Before I was getting a memory error but this time I am not getting any errors at all. Only no video or audio. The only part of the tutorial I did not use was the last part about the ipad rotation because I'm not worried about that.
The only part I was unable to follow exactly was putting the video in the resources folder because xcode 4.5.2 does not make one. So I put MOVIE.MOV in the same directory as my .h, .m and .xib files were automatically placed in. I have tested the video and it does work on its own.
Here is the code: any help or guidance would be appreciated. Sorry for being such a NOOB.
the header:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController{
}
-(IBAction) playMovie;
#end
the main:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)playMovie
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"MOVIE" ofType:#"MOV"]];
MPMoviePlayerController *moviePlayer =
[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer
respondsToSelector:#selector(setFullscreen:animated:)])
{
[moviePlayer.view removeFromSuperview];
}
[moviePlayer release];
}
Thankyou very much for any help.
Some things you could check:
Did you check the "Copy item to destinations group folder" when you dragged the movie onto the Xcode project?
Does the item show up in the "Copy Bundle Resources" Build Phase? (click on the Project, Select your target and check the "Build Phases" tab in Xcode)
Paths strings are case-sensitive on iOS. Does your movie really have the file name "MOVIE" and the extension "MOV" (all upper-case)?
Related
Is it just me or _UIImagePickerControllerUserDidCaptureItem notification from uiimagepickercontroller stopped working on iOS 8 and XCode 6. I use it to rotate the camera overlay after the user taked a picture.
PLease help
It's pretty strange, but in iOS 8 setting observer using
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(imagePickerControllerDidCapture) name:#"_UIImagePickerControllerUserDidCaptureItem" object:nil];
doesn't work for UIImagePickerController, but using block works fine:
self.imagePickerControllerDidCaptureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:#"_UIImagePickerControllerUserDidCaptureItem" object:nil queue:nil usingBlock:^(NSNotification *note) {
[self removeCameraOverlay];
}];
Please notice that in this approach you should store observer object to detach it later using
[[NSNotificationCenter defaultCenter] removeObserver:imagePickerControllerDidCaptureObserver];
In situations like that it very useful to use
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(#"Notification: %#", note.name);
}];
to monitor all notifications, see names and moments it fires.
I also see the same issue with iOS 8 but using block works as mentioned by Amoneron in his answer.
Here's how to do it in Swift:
NSNotificationCenter.defaultCenter().addObserverForName("_UIImagePickerControllerUserDidCaptureItem", object:nil, queue:nil, usingBlock: { note in
// do something here
})
It still works for me, though I am using the notification center for that.
NSNotificationCenter.DefaultCenter.AddObserver (new NSString ("_UIImagePickerControllerUserDidCaptureItem"), HandleUserCapturedItem);
the code is in c# as I am using xamarin to develop, there should be something similar in objective-c since I'm basically using wrapper classes (built by xamarin).
#import "AppDelegate.h"
#import <MapKit/MapKit.h>
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
[self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
[self.window makeKeyAndVisible];
UIViewController *vc = [[UIViewController alloc] init];
self.window.rootViewController = vc;
vc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
MKMapView *map = [[MKMapView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
map.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[vc.view addSubview:map];
return YES;
}
#end
To see the problem, run the above code and just rotate the device.
You will experience a significant delay for the rotation animation to take place.
If you connect an iOS8 iPad and run the simulator,
you will receive these warnings:
Crash! 0x15dd7980
ERROR /SourceCache/VectorKit/VectorKit-992.16/GeoGL/GeoGL/GLCoreContext.cpp 1237: Framebuffer incomplete, incomplete attachment
Anyone know how to fix this problem?
I am also experiencing this, and have found that it only seems to occur with the resizing options selected (i.e. resize height and width with as view resizes). I'm not using Auto Layout.
If I just add a MKMapView to a view, it's no problem, but if I select the resizing, it generates the same messages as shown above.
(Sorry that this is a comment not an answer, but I can't add comments on 1 vote, and I thought this may help diagnose the issue)
UPDATE - I have installed 8.1 Beta on one of my test devices, and I am NOT experiencing this issue. There is a good chance this is an issue that's being swept under the 8.1 carpet :)
I had this issue recently and adding the constraints in code worked until I updated the app to be iPhone 6/ 6+ optimized, in that case I could still see the errors in the console log and it was in a bright pink color.
The best solution was to add the MKMapView directly on the storyboard, all messages and weird color behaviors were solved
I have a problem here, which I couldn't find a solution yet.
In my app, I have a tableView which parses the youtube videos from my channel. If selecting an item, it pushes to a UIWebView, which shows the youtube website with my video embedded.
However, when I tab play on the iPhone it opens the native fullscreen player. But on the iPad there are two issues:
It doesn't open in fullscreen, the navigation bar still remains visible. Also it's not the native player but the a resized youtube player.
My vids are all in 1080p, however on the iPad I can only select 720p.
Here is the code from my WebView:
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController ()
#end
#implementation ViewController
#synthesize videoURL = _videoURL;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:self.videoURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
And here from the header file:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#property (nonatomic, strong) NSString *videoURL;
#end
How can I make it to use the native player on iPad as well? And is there a possibility to open the video directly without showing the youtube website? I've already tried to select and deselect "Allow inline rendering" with no change of the behavior.
I appreciate your help...
Here is a link to my solution for a similar Thumbnail -onTouch-> Fullscreen on iPad and iPhone need. https://stackoverflow.com/a/25695708/3397249
I have App, playing Videos from web
everything works fine
but when user leave the app for reading email or anything
and come back the player gone!! big problem
so, I want user resume watching after come back to app
here is my code so far
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didEnterforground) name:UIApplicationWillEnterForegroundNotification object:nil];
the Methods
- (void) didEnterBackground
{
[theMovie.moviePlayer pause];
NSLog(#"Playing pause");
}
- (void) didEnterforground
{
[theMovie.moviePlayer play];
NSLog(#"Playing resume");
}
for know I use [self presentMoviePlayerViewControllerAnimated:theMovie]; NOT playing in view
should that's code works but, nothing works
Please Help
Thanks in advance
The answer is very simple, edit info.plist.
Add background competence, required background modes, set category App plays audio
Try it!
This is a Cocoa app I am working on. I'm trying to embed a simple WebView with some basic content in an NSWindow in my app. I've wired my WebView to my NSWindowController, and anytime I try to pass a selector to that WebView, things are fine. But to load content, I need to use the WebFrame. And XCode refuses to recognize any methods in WebFrame (although it seems to recognize that WebFrame is a proper class.) For example:
[[webView mainFrame] loadHTMLString:htmlString baseURL:nil];
generates a 'loadHTMLString: baseURL:' not found compiler warning. It does function at runtime, but of course I'd like to eliminate the compiler warning.
Any thoughts on what's up?
Thanks in advance.
(Edited to add more code)
Below is from my ViewController's header file:
#import <Foundation/Foundation.h>
#import <WebKit/WebView.h>
#interface ReportViewController : NSWindowController {
IBOutlet WebView *webView;
}
#property (nonatomic, assign) WebView *webView;
And below here is a snippit from my Document implementation:
ReportViewController *window = [[ReportViewController alloc] initWithWindowNibName:#"Report"];
[window showWindow:nil];
WebView *webView = [window webView];
[htmlData writeToFile:tmpfile atomically:YES];
Thanks to Bavarious' hint, I realized that I needed to import <WebKit/WebKit.h> as opposed to <WebKit/WebView.h>.