how to add custom button in MPMoviePlayerViewController? - iphone

I have a project to play videofile through MPMoviePlayerViewController,
that process i was finished.in MPMoviePlayerViewController, how i add button like conrols.

MPMoviePlayerViewController is just like any other view controller. You should be able to set up your own custom view and then hook up your buttons to the moviePlayer contained in the MPMoviePlayerViewController

are you want to creating the customization of the MPMovieViewController for that below code is use to create the customized Moviecontroller..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
MainScreenVCtr *tempVariable=[[MainScreenVCtr alloc] initWithNibName:(UI_USER_INTERFACE_IDIOM())?#"MainScreeniPad":#"MainScreenVCtr" bundle:nil];
self.nvCtr=[[UINavigationController alloc] initWithRootViewController:tempVariable];
self.nvCtr.view.frame=CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height-20);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self.window addSubview:self.nvCtr.view];
self.vCtr=[[CustomControllsVCtr alloc] initWithNibName:(UI_USER_INTERFACE_IDIOM())?#"CustomControllsiPad":#"CustomControllsVCtr" bundle:nil];
[self.window makeKeyAndVisible];
return YES;
}
And refer the reference link and Download the source code and implementation tutorail given here.
Hope this tutorial help to you create customized MPViewcontroller .
Happy Codeing

Related

Volume Detection In IOS 6

I am creating a app in which when the app is in background and user changes the volume in iPhone app should came to know about it.
Any ideas or clues?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(volumeChanged:)
name:#"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
LoginVC *login=[[LoginVC alloc]initWithNibName:#"LoginVC" bundle:nil];
self.navigate=[[UINavigationController alloc]initWithRootViewController:login];
[self.window addSubview:navigate.view];
[login release];
[self.window makeKeyAndVisible];
return YES;
}
- (void)volumeChanged:(NSNotification *)notification
{
float volume =
[[[notification userInfo]
objectForKey:#"AVSystemController_AudioVolumeNotificationParameter"]
floatValue];
NSLog(#"chfi");
// Do stuff with volume
}
I Have Used This code But its not getting Called.
You can set a listener. When volume changed, the call back method will be getting called.

How to use mp4 file as a Splash screen for my iphone application instead of Default.png

Could any-one please explain me....it's possible in iphone. if yes then could you explain step by step because i am new in iphone development.
The closest you could do would be to have a png image as the splash which contains the 1st frame of the video you want to play and then play a video ASAP.
Some basic code to get you started might look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playBackDidFinishNotification:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSURL *URL = [[NSBundle mainBundle] URLForResource:#"clip" withExtension:#"m4v"];
MPMoviePlayerViewController *viewController = [[MPMoviePlayerViewController alloc] initWithContentURL:URL];
viewController.moviePlayer.fullscreen = YES;
viewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[viewController.moviePlayer play];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)playBackDidFinishNotification:(NSNotification *)notification;
{
self.window.rootViewController = [[PSRootViewController alloc] init];
}

Display a Splash Screen Before Loading the Root Navigation Controller - iPhone

I am new bee in iPhone. I have implmented using some tutorials, a Splash Screen before loading the UIViewController. Now i want to implement a NavigationController in my application and want to display a Splash Screen before it. Since I am new in Iphone so i did not get any tutotrials or guides to make a Splash Screen before loading a Root Navigation Controller.
I have seen many methods in which they over write the Default.png file and so on. I dont want to implement that one. I want a sperate UIView to have my custom Images and text in it and display that UI View as a Splash Screen
can anybody Guide me please.
Thanks in advance
Here you go buddy. Have fun and happy coding....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Add a splash screen
UIImageView *imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"splash.png"]];
imgv.userInteractionEnabled = YES;
[navigationController.view addSubview:imgv];
[imgv release];
[self performSelector:#selector(removeSplash:) withObject:imgv afterDelay:3.0];
[window addSubview:navigationController.view];
return YES;
}
- (void)removeSplash:(UIImageView *)imageView {
[imageView removeFromSuperview];
}
Use "self.window" to display the splash image first. If u simply write "window", the image will not be displayed and animated in the first view, since the image can't be directly linked to the window in that case. Write the following code in appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
UIImageView *imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"themes.png"]];
imgv.userInteractionEnabled = YES;
[self.navigationController.view addSubview:imgv];
//[imgv release]; If you don't use ARC, uncomment this.
[self performSelector:#selector(removeSplash:) withObject:imgv afterDelay:3.0];
[self.window addSubview:self.navigationController.view];
return YES;
}
- (void)removeSplash:(UIImageView *)imageView
{
[imageView removeFromSuperview];
}

How to switch from one UIViewController to another?

I have a problem with switching from one viewcontroller to another.
Here is what I have :
In my "AppDelegate_iPad.m" :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor blackColor];
LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:#"LoginViewController_iPad" bundle:nil];
[window addSubview:loginView.view];
[self.window makeKeyAndVisible];
return YES;
}
That works. Now I have a login button on that screen and when pressed it calles this :
- (IBAction)doPressLoginButton
{
DebugLog(#"doPressLoginButton");
MenuViewController_iPad *menuView = [[MenuViewController_iPad alloc] initWithNibName:#"MenuViewController_iPad" bundle:nil];
[self.navigationController pushViewController:menuView animated:YES];
[menuView release];
}
The problem is that nothing happends. I assume I am missing the actual navigationconroller ?!
Hope that anyone can help.
Thank you
You should create a UINavigationController instance variable in your app delegate. Then, make sure you synthesize it and release it in your dealloc method.
Your implementation of application:didFinishLaunchingWithOptions: could look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// window is usually an IBOutlet
CGRect frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor blackColor];
LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:#"LoginViewController_iPad" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:loginView];
[loginView release];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
Now you'll be able to use self.navigationController.
I assume I am missing the actual navigationconroller ?!
you are right. :D
self.navigationController returns nil if you don't set up an NavigationController.
And any messages send to nil object will be ignored.
If you only need switch from one to another.
using
[self presentModalViewController:modalViewController animated:YES];
instead.

How do I display video from AppDelegate in iOS4

Now I think I know about the differences between 3.X and 4 with regards the MPMoviePlaybackController and the need to set the view and have it fully working in a child view controller. But despite the following code seeming correct (to me) I still just get a blank screen for the duration of the movie. I know it plays successfully as moviePlayBackDidFinish fires.
Do I need to add it to a modal or similar at this point?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
player.fullscreen = YES;
player.controlStyle = MPMovieControlStyleNone;
[[player view] setFrame:window.bounds];
[window addSubview: [player view]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
}
the MPMoviePlayerController does NOT have a view property.
you should/must use MPMoviePlayerViewController instead.
here's what I do:
moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:currentChannel.StreamURI]];
[moviePlayerViewController.moviePlayer setControlStyle:MPMovieControlStyleNone];
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
moviePlayerViewController.moviePlayer.shouldAutoplay = YES;
[moviePlayerViewController.moviePlayer setScalingMode: MPMovieScalingModeAspectFit];
moviePlayerViewController.view.frame = CGRectMake(0, 0, 480, 320);
[self.view addSubview:moviePlayerViewController.view];
note that you might want to change movieSourceType to MPMovieSourceTypeFile or MPMovieSourceTypeUnknown.
The above code is 100% of what I need to play a Movie (in my case a streaming channel)
In my case I had moved the
[window makeKeyAndVisible];
Out from
didFinishLaunchingWithOptions
and into my
movieDidFinish
By putting it back it worked