No "Done" button at AVPlayerViewController Objective C - objective-c

I can't seem to create the "Done" button at my video. I have attached my code below:
- (IBAction)playVideoButton:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:#"Video1" ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
//to view on full UIScreen
self.mc = controller;
controller.view.frame = self.view.bounds;
[self.view addSubview:controller.view];
[player play];
}

You were not using the AVPlayerViewController class properly. Here is how you are supposed to use it:
- (IBAction)playVideoButton:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:#"Video1" ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[self presentViewController:controller animated:YES completion:nil];
}
With that, you'll have the "Done" button comes with AVPlayerViewController along with other playback buttons (e.g. pause/resume and etc.).

Related

Objective C notify application when call is ended [duplicate]

I am trying to initiate a call from my iphone app,and I did it the following way..
-(IBAction) call:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Call Besito" message:#"\n\n\n"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *phone_number = #"0911234567"; // assing dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phone_number]]];
NSString *phone_number = #"09008934848";
NSString *phoneStr = [[NSString alloc] initWithFormat:#"tel:%#",phone_number];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];
}
}
by the above code..I am able to successfully make a call..but when I end a call,I'm not able to return to my app
So, I want to know how to achieve,that..also please tell me how we can initiate a call using webview...
This is my code :
NSURL *url = [NSURL URLWithString:#"telprompt://123-4567-890"];
[[UIApplication sharedApplication] openURL:url];
Use this so that after call end it will return to app.
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:+9196815*****"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
Please try this it will definitely let you Back to Your App.
NSString *phoneNumber = // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
following code will not return to your app [no alertview will show before make call]
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
following code will return to your app "alertview will show before make call"
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
You can also use webview, this is my code :
NSURL *url = [NSURL URLWithString:#"tel://123-4567-890"];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 100)];
[self.view addSubview:btn];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(50, 50, 150, 100)];
webview.alpha = 0.0;
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:btn];
[webview release];
[btn release];
It's not possible to return back to the app after ending a call because it's an app.

Video players for mov files?

I am using MpMovieplayer to play mov files dynamically(selecting videos from devices) in ios 5 but it is not playing.It shows blackscreen.I also tried directly movie url giving to player but it doesn't work.Is there any player instead of MPMovieplayer to play mov files.Thanks in advance
NSString *path = [[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"mov"];
NSURL *movieURL = [NSURL fileURLWithPath:path];
NSLog(#"movieURL ----%#",movieURL);
movieplayer=[[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if([movieplayer respondsToSelector:#selector(view)])
{
movieplayer.controlStyle = MPMovieControlStyleFullscreen;
[movieplayer.view setFrame:self.view.bounds];
[self.view addSubview:movieplayer.view];
movieplayer.shouldAutoplay=true;
[movieplayer play];
}
try
NSString *path = [[NSBundle mainBundle] pathForResource:#"your movie" ofType:#"mov"];
MPMoviePlayerViewController* tmpMoviePlayViewController=[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
if (tmpMoviePlayViewController) {
tmpMoviePlayViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tmpMoviePlayViewController animated:YES];
tmpMoviePlayViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieViewFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:tmpMoviePlayViewController];
[tmpMoviePlayViewController.moviePlayer play];
}
You should take a look at the AVPlayer class.
MPMoviePlayerController is actually 'derived' from the AVPlayer class so that could make it work.

playing video in objective c

I try this but not work I can hear the sound but I can't see the image..How can I solve this??
in app delegate class:
- (IBAction)tanitimVideo:(id)sender {
// create our UnifeyeMobileViewController and present it
video* unifeyeMobileViewController = [[video alloc] initWithNibName:#"video" bundle:nil];
unifeyeMobileViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController presentModalViewController:unifeyeMobileViewController animated:YES];
[unifeyeMobileViewController release];
}
in video.m class:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
Try using MPMoviePlayerViewController instead, very little code to get it working and you can do it all from your app delegate ;)
- (IBAction)tanitimVideo:(id)sender {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[self presentMoviePlayerViewControllerAnimated:mp];
[mp release];
}
Look at your .m file-
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
////////// <<<<<>>>>>>>>>> //////////
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc]
initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
why do you make 2 controllers (theMovie , moviePlayer) and you setting all in theMovie but running the moviePlayer.
it's should be like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie setShouldAutoplay:YES];
[self presentMoviePlayerViewControllerAnimated:theMovie];
}
hope it's help.

i have two mpmovieplayercontrollers and two separate subviews that they utilze... except that only one video will play at a time

I would like to have both movies playing at once in their two separate sub views. They are both accessing different media.
this is on an ipad with a superview and two little views 320x240 right by eachother on the xib.
-(IBAction)playLeft:(id)sender{
if ([self.playerRight playbackState] == MPMoviePlaybackStatePlaying);
[self.playerRight stop];
[self.playerLeft play];
}
-(IBAction)playRight:(id)sender{
if ([self.playerLeft playbackState] == MPMoviePlaybackStatePlaying);
[self.playerLeft stop];
[self.playerRight play];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
self.playerLeft = [[MPMoviePlayerController alloc] init];
self.playerLeft.contentURL = [self movieURL];
NSLog(#"self.playerLeft %#", self.playerLeft);
self.playerRight = [[MPMoviePlayerController alloc] init];
self.playerRight.contentURL = [self movieURL2];
NSLog(#"self.playerRight %#", self.playerRight);
// START_HIGHLIGHT
self.playerLeft.view.frame = self.leftView.bounds;
self.playerLeft.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.playerRight.view.frame = self.rightView.bounds;
self.playerRight.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
[self.rightView addSubview:playerRight.view];
[self.leftView addSubview:playerLeft.view];
//[self.playerRight play];
//[self.playerLeft play];
//[self clickedOpenMovie:nil];
}
-(NSURL *)movieURL
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath =
[bundle
pathForResource:#"720p5994-prores-hq_iPhone_320x240 two"
ofType:#"m4v"];
//NSString *moviePath = [NSString stringWithFormat:#"http://localhost:1935/live/aStream/playlist.m3u8"];
if (moviePath) {
return [NSURL fileURLWithPath:moviePath];
//return [NSURL URLWithString:moviePath];
} else {
return nil;
}
}
-(NSURL *)movieURL2
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath =
[bundle
pathForResource:#"720p5994-prores-hq_iPhone_320x240"
ofType:#"m4v"];
if (moviePath) {
return [NSURL fileURLWithPath:moviePath];
} else {
return nil;
}
}
so the problem is that somewhere in the background MPMoviePlayerController responds to notifications and turns itself off if another MPMoviewPlayerController broadcasts that its going to start. Thus one can not have multiple MPMoviePlayerControllers playing at the same time.
you can see this by printing out the MPMoviePlayerPlaybackStateDidChangeNotification

Playing video and audio in iPhone not working

So we have buttons linked up to display images/videos/audio on click depending on a check we do earlier. That part works fine. It knows which one to play, however, when we click the buttons for video and audio, nothing happens. The image one works fine.
The video and audio are being taken for a URL online, they are not local, but everywhere said this was still possible. Here is a little snippet of the code where we play the two files:
if ( [fName hasSuffix:#".png"])
{
NSLog(#"PICTURE");
NSURL *url = [NSURL URLWithString:
fName];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
// self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"MainBG.jpg"]];
[self.view addSubview:[[UIImageView alloc] initWithImage:image]];
}
if ( [fName hasSuffix:#".mp4"])
{
NSLog(#"VIDEO");
//NSString *path = [[NSBundle mainBundle] pathForResource:fName ofType:#"mp4"];
//NSLog(path);
NSURL *url = [NSURL fileURLWithPath:fName];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[player play];
}
if ( [fName hasSuffix:#".mp3"])
{
NSLog(#"AUDIO");
NSURL *url = [NSURL fileURLWithPath:fName];
NSData *soundData = [NSData dataWithContentsOfURL:url];
AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc] initWithData:soundData error: nil];
[avPlayer play];
}
See anything wrong? By the way it compiles and runs, but nothing happens when we hit the button that executes that code.
I am not sure why they are not playing, does it ever reach the video and audio conditons?
Either way your currently missing before you play the movie
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification object:player];
You will then need the function to handle the callback
-(void)movieFinishedCallback:(NSNotification *)notification{
NSLog(#"MOVIE FINISHED");
if(player == [notification object]){
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player release];
player = nil;
}
}