MPMoviePlayerViewController, remove quicktime symbol/add background image? - iphone

I have an MPMoviePlayerViewController that plays audio. I would like to remove the Quicktime logo and/or add a custom background image to the player but keep the playback controls. I swear I have done this before prior to iOS 5 but I can't re-figure it out! Things I have tried:
-Adding a subview to MPMoviePlayerViewController. Puts the subview OVER the playback controls, not good.
-setBackgroundColor of the moviePlayer with a patternimage. Doesn't do anything.
-setView on the entire MPMoviePlayerViewController. As expected, the playback controls and navigation bar are gone. I suppose this could work but I'd need to recreate all the playback controls manually, but I'd really rather not.
Can anyone shed some light?

Check out the MPMoviePlayerController property backgroundView.
From the MPMoviePlayerController Class Reference;
backgroundView
A customizable view that is displayed behind the movie
content. (read-only)
#property (nonatomic, readonly) UIView *backgroundView
Discussion This
view provides the backing content, on top of which the movie content
is displayed. You can add subviews to the background view if you want
to display custom background content.
This view is part of the view hierarchy returned by the view property.
Availability Available in iOS 3.2 and later. Declared In
MPMoviePlayerController.h
Try something like this (assuming that your instance of the MPMoviePlayerController is called moviePlayerController):
patternView = [[UIView alloc] initWithFrame:self.view.bounds];
patternView.backgroundColor = [UIColor redColor];
[moviePlayerController.backgroundView addSubview:patternView];
[patternView release];

Till's answer is correct for iPhoneOS 3. This has changed in iOS 4 and 5.
Apple has now added a readonly property to MPMoviePlayerViewController exposing a MPMovieController. The MPMovieController has a backgroundView that should be used.
Now you will want to do something like this:
patternView = [[UIView alloc] initWithFrame:self.view.bounds];
patternView.backgroundColor = [UIColor redColor];
[moviePlayerController.moviePlayer.backgroundView addSubview:patternView];
[patternView release];

Related

Adding a splash screen to my project

I have created a project which consist of a tabbarcontroller and a navigationcontroller.
The first view or the first tab is a tableview controller. Now i need to add a splashscreen to my application, so when the app loads it will show a welcome screen and then land on the tableviewcontroller.
My workings so far;
This is added in my viewDidLoad method.
myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"splash.jpg"]];
myImageView.frame = [[self view] frame];
[self.view addSubview:myImageView];
[self.view bringSubviewToFront:self.myImageView];
The problem is that the splash screen or the UIImageView loads inside the tabbarController/NavigationController, and it does not take the full width and length of the screen. What should i do to fix this programatically ?
In application bundle you need to copy the splash screen images with the name "Default.png" and "Default#2x.png" for Retina. The app will load this automatically, you don't need to do more work.
Here you have a link for this: http://iosdevelopertips.com/cocoa/defaultpng-the-secret-of-the-load-screen.html
Add the images that you want to use to the resources of your project and name them Default.png and Default#2x.png (if you are providing it for a retina screen). Be sure no name them exactly. If you get the capitalisation wrong, it will work in the Simulator (which is not case-sensitive), but not on the device (which is case-sensitive).
Be aware that a "splash screen" is discouraged by the Apple Human Interface Guidelines:
Have you given the Launch Images a look in your target settings?
You would probably want to add the splash screen in the app delegate's didFinishLaunchingWithOptions method. Then start an animation of fade out (or whatever animation you need). Finally removing the splash screen view when the animation is complete.
You have to add the UIImageView to the root's view:
UIView *rootView = [[[[UIApplication sharedApplication] delegate] viewController] view];
[myImageView setFrame:rootView.bounds];
[rootView addSubview:myImageView];
you can use the uiimage view to add an array of images to play an animation, try the following
code in
-(void)viewDidAppear:(BOOL)animated {
animationSplashImageView.animationImages = imageArray;
animationSplashImageView.animationDuration = 5;
animationSplashImageView.animationRepeatCount = 1;
[animationSplashImageView startAnimating];
}
IBOutlet UIImageView* animationSplashImageView;
was defined in the main view of your app.
also you could test your splash using tool Splashx Free, which is on Apple App Store: http://itunes.apple.com/cn/app/splashx-free/id500137095?mt=8

custom UINavigationBar background in MFMailComposeViewController

I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UINavigationBar to achieve this throughout my app, but Apple specifically requests that you do not do this. Additionally this may or may not work in future versions of iOS that are currently under NDA.
I am now using a subclass of UINavigationBar to achieve the look I'm after in the rest of the app, but I can't see any way to use this with the MFMailComposeViewController. Any ideas?
Note: I'm aware of methods to do this in a future version of iOS, but this needs to be built against a current version (4.3) of the SDK.
I just ran across this -- you can dynamically inject the class a view controller uses using object_setClass.
#import <objc/runtime.h>
object_setClass(mailController.navigationBar, [YourNavigationBarSubClass class]);
You can customize the nav bar's titleView with a custom view using the code below. Expanding upon this idea, you may be able to resize the titleView to cover the entire navigation bar and use a custom background in that to simulate a custom navbar background.
The only possible sticky part I can think of is that you need to make sure the titleView sits behind the buttons in the toolbar.
Once you have your MFMailComposerViewController reference, here is the code to customize the titleView:
[self presentModalViewController:controller animated:YES];
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(//set size to navbar size)];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage://your custom image ]];
controller.topViewController.navigationItem.titleView = backgroundView ;
[controller release];
The mail composition interface itself is not customizable and must not be modified by your application.
check apple reference for more info...
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
but we can customizable the mail composition as given oin the above answer....
After some hacking and testing, still not manage to customize the button. But this is the closest I can get, by setting the tint color of mail controller.
Try accessing them through mailController.navigationBar.items, which is an array of the bar items.
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
mailController.navigationBar.tintColor = [UIColor brownColor];
Although it would be nice to get more control over the appearance, I don't think there is a clean method. When you cant change it...hide it:
NSDictionary *attributes = #{NSForegroundColorAttributeName: [UIColor clearColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

Playing videos on iPad with a specific style

i have some mp4 files which are to be played in my iPad app.. I am able to do that quite well. right now i have a play button on blank black space in my app and the video plays after i tap the play button. The user will only come to know the content of the video after playing it.. But, i want the user to know about the video before playing itself . instead of the default black screen i want to show the video starting screen to make the video more interesting. To put it in simple words, i want my video space to be similar to youtube... IS there any way i which this can be done?? Thanks
Subclass MPMoviePlayerController (or however you're playing your video.. if you already use a custom class just add the code in there) and in viewDidAppear initialise a UIImageView with frame size equal to self.view.bounds using whatever background image you want for the loading screen. Add the UIImageView as a subview of self.view and call sendSubviewToBack: on it. When the player is ready to play, it will start drawing video frames on top of your subview, and you should not see it again.
- (void)viewDidAppear
{
UIImageView *loadingImage = [[UIImageView alloc] initWithImage:myImage];
[loadingImage setFrame:self.view.bounds];
[self.view addSubview:loadingImage];
[self.view sendSubviewToBack:loadingImage];
[super viewDidAppear];
}

AirPlay support, MPMoviePlayerController and MPVolumeView relation

I am developing an iPhone application that has support for video play. I am using MPMoviePlayerController with custom controls for playing the video. For this purpose I have set control style of MPMoviePlayerController to MPMovieControlStyleNone.
I would like to support AirPlay feature for the video being played. As per the documentation, we have to set the 'allowsAirPlay' property of MPMoviePlayerController to YES to enable AirPlay feature. How can I display the AirPlay button on my player UI if I am using MPMoviePlayerController with custom controls?
I have tried the following:
Instantiated MPVolumeView
Set the showsRouteButton and showsVolumeSlider properties of MPVolumeView to NO to hide the volume slider and route button
Added MPVolumeView on my custom player View
I have not given the reference of MPVolumeView and MPMoviePlayerController to each other. But, if 'allowsAirPlay' of MPMoviePlayerController is set to YES then AirPlay button gets displayed on MPVolumeView. How are MPVolumeView and MPMoviePlayerController related? What is the connection between these two classes which are created independently?
Since the MPMoviePlayerController only allows you to play one video at a time, the MediaPlayer framework always knows the video that's playing. That's how MPVolumeView knows about the MPMoviePlayerController. I have no official docs, but I imagine it's baked into the framework this way.
Since there are probably a lot of checks and balances going on (and they loves consistent UIs), Apple only allows you to use their AirPlay button/UI for tapping into this feature. You can, however, put that button wherever you want:
airplayButton = [[MPVolumeView alloc] init];
airplayButton.frame = CGRectMake(myX, myY, 40, 40);
[airplayButton setShowsVolumeSlider:NO];
[customPlayerControls.view addSubview:airplayButton];
I just guessed on the width,height being 40,40 and I'm sure it's not correct, but once I got the button in place it didn't matter.
for (UIButton *button in volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
[button setImage:[UIImage imageNamed:#"custom-route-button.png"] forState:UIControlStateNormal];
[button sizeToFit];
}}
I think this will help you.
The MPVolumeView has an attribute to hide the volume slider and to show the Route button. So there is no need to traverse the views hiding things.
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:myContainerView.bounds] autorelease];
volumeView.showsVolumeSlider = NO;
volumeView.showsRouteButton = YES;
[myContainerView addSubview:volumeView];
The placement of the AirPlay (Route) button may not be what you expect so you may have to play the frame of the container view a bit to get it where you want it.
The answer is: you can't. There is no official method as of iOS 4.3 to provide your own controls for Airplay - you need to use the standard controls if you need that functionality.

MPMoviePlayer Audio Album art

I am streaming an MP3 file using MPMoviePlayer, and I would like to have an image displayed instead of the default Quicktime logo in the background.
I found out a way to have an image overlay the player, but the problem with that, is you have to tap outside the image to get the player controls to appear. And when they do appear, they are underneath the image.
Does someone know how to do this?
Thanks,
John
backgroundColor is deprecated, and diving into private View structures is dangerous. This worked fine for me:
UIImageView *coverImageView = [[UIImageView alloc] initWithImage:coverImage];
coverImageView.contentMode = UIViewContentModeScaleAspectFit;
coverImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
coverImageView.frame = moviePlayerController.view.bounds;
[moviePlayerController.view addSubview:coverImageView];
Most every app on the iPhone is made of a hierarchy of views. You could go up to the top root node of the movie player and walk down the child views recursively and set the hidden value to YES until you find the right item, then insert your UIImageView below that item. That way, the controls stay on top and still respond to user inputs.
The risk you run is if Apple changes the MPMoviePlayer UI and shuffles the view hierarchy, but you'll probably have lots of advance notice and can patch your app to allow for the new layout.
There is a question as to whether this is kosher for appstore apps, but many current apps (especially camera/picture-taking ones) are doing it to get rid of standard window elements.
Use AVAudioPlayer and implement your own player UI.
it will work check this
MPMoviePlayerController *moviePlayerController=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
moviePlayerController.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Default.png"]];