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.
Related
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.).
I am implementing MFMailComposeViewController in my application when I click on my mail button I am get the below error.
Application tried to present a nil modal view controller on target strong text
Here's my code:
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleVersion"];
mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.navigationBar.tintColor = [UIColor blackColor];
[mailComposer.navigationBar setTitleTextAttributes:
#{NSForegroundColorAttributeName:[UIColor blackColor]}];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:#"Co - Contact Us"];
[mailComposer setToRecipients:#[#"contact#co.org"]];
NSString *supportText = #"Enter your comment here:\n\n\n\n\n";
supportText = [supportText stringByAppendingString:[NSString stringWithFormat:#"iOS Version: %#\nCorner Version:%#\nBuild:%#\n\n",iOSVersion,version, build]];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
What's wrong with my code. Please help
If device has not configured mail or using simulator can lead to crash or exception.
mailComposer = [[MFMailComposeViewController alloc] init];
above line of code can cause problem. in simulator initializer method may return NULL or nil.
so, just check for canSendMail before presenting modal viewController:
Like,
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleVersion"];
mailComposer = [[MFMailComposeViewController alloc]init];
if ([MFMailComposeViewController canSendMail] && mailComposer) {
mailComposer.navigationBar.tintColor = [UIColor blackColor];
[mailComposer.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor blackColor]}];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:#"Corner - Contact Us"];
[mailComposer setToRecipients:#[#"contact#corner.org"]];
NSString *supportText = #"Enter your comment here:\n\n\n\n\n";
supportText = [supportText stringByAppendingString:[NSString stringWithFormat:#"iOS Version: %#\nCorner Version:%#\nBuild:%#\n\n",iOSVersion,version, build]];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
}
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.
i've got a sound which is started when the app starts, it's 30 seconds long. how can I repeat the song when it's over no matter in which viewcontroller i am?
my code:
-(void)playBgMusic {
NSString *path = [[NSBundle mainBundle] pathForResource:#"bgmusic" ofType:#"aif"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play]; }
-(id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if(self)
{
[self playBgMusic];
}
return self; }
Try
theAudio.numberOfLoops = -1
Look at Apple's Documentation for more info.
The owner of the audioPlayer instance should be the appDelegate then to let it play wherever the user is in the app.
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