I am creating a movie appliction in iphone/ipod .i have added a video to it . when i run it in simulator it runs properly in portrait mode.But when i run my app in ipod it opens a blank video and in landscape mode .but in simulator when i click on play my video directly plays in portrait mode and in ipod it opens a blank video in landscape mode which i want in portrait mode
This is my code for video:
-(IBAction)video1:(id)sender
{
NSBundle *bundle =[NSBundle mainBundle];
NSString *moviepath =[bundle pathForResource:#"CRY CRY - 90 Sec Video" ofType:#"mov"];
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];
}
Please help me in solving this problem.
What version of iOS is your iPod running? Version 3.x will always open videos in landscape mode, version 4.x will open videos in the current orientation.
Related
I'm using an MPMoviePlayerController for playing video in my iPhone app.
When MPMoviePlayerController is playing, press home button on iPhone, make the app enter background.
Then tap the app's icon to make the app enter foreground, the MPMoviePlayerController's view will be black screen for a short time, about 1 to 15 seconds.
How to make the MPMoviePlayerController's video shows immediately when app came to foreground?
Special thx! :D
NSURL *movieURL = [NSURL URLWithString:#"http://......"];
// Initialize a movie player object with the specified URL
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self.moviePlayer.view setFrame:self.view.bounds];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer play];
I Hope this will help You.
i am develop app with avaudioplayer it's works perfectly, but,my problem is if my iPhone vibrate mode to open my app avaudioplayer plays audio little bit below seconds, i want to not play a avaudioplayer sound in vibrate mode.
here's my code:
- (void)viewDidLoad
{
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL
fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"audio" ofType:#"mp3"]] error:NULL];
audioPlayer.numberOfLoops =-1;
audioPlayer.delegate = self;
audioPlayer.currentTime=0.0f;
[audioPlayer prepareToPlay];
[audioPlayer Play];
}
can any one help me please..!
Thanks..!
Try:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error: nil];
As stated in the Apple Docs:
AVAudioSessionCategoryAmbient
For an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off.
This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays over iPod audio. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).
Should be what you're looking for specifically.
Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone)
I'm playing video with MPMoviePlayerViewController. I get video url from web service. But first I select video quality with AlertView. For example 240p 360p 480p… All video plays except 240p. MPMoviePlayerView appears and then disappears with notification MPMovieFinishReasonPlaybackEnded. I try to play url of 240p video in simulator, everything is perfect but in device it's not playing. I receive MPMovieFinishReasonPlaybackEnded all the time. If I select 360p or more, everything is good. Here is some code:
-(void) playVideoFromURL:(NSString *) url
{
NSLog(#"%#",url); //URL is valid! Browser plays it
if (!videoPlayerView) {
NSURL *fURL = [NSURL URLWithString:url];
videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:fURL];
videoPlayer = videoPlayerView.moviePlayer;
[videoPlayer prepareToPlay];
}
}
It doesn't play even from the local folder. This is an iPhone app, my device is iPad 2!
My MediaPlayerViewController developed this funny thing of rotating into view! My whole app is landscape based, but the MediaPlayerViewController seems to rotate from portrait to landscape and when finished the previous view would then also rotate from portrait into its original landscape orientation. This will not happen in a small test app. Only when the app becomes complicated. I have tried preloading the movie, doesn't help, i have tried didRotatefromInterfaceOrientation, nothing. I have my supported orientations set and to return UIInterfaceOrientationIsLandscape. My code for the movie if that might help:
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"BearA-least" ofType:#"mov"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentModalViewController:moviePlayer animated:NO];
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer.moviePlayer play];
I'm new to developing and have been struggling with this problem for a while. Any input would be greatly appreciated. I've seen people having similar problems with views rotating.
As I see, you're using MediaPlayerViewController and presenting it using presentModalViewController
MoviePlayerViewControllers are usually displayed using [self presentMoviePlayerViewControllerAnimated:(PlayerViewController)]
As I can see, you're preventing your user from controlling the playback -> MPMovieControlStyleNone
Hint: You might also want to set the movieSourceType property on your MoviePlayerController.
For controlling the orientation in a way as you're trying to achieve, I would suggest you to subclass MPMoviePlayerViewController and listen for notifications sent by the MPMoviePlayer on the various movie playback events.
How do I add a video to an iPhone app. using iPhone SDK 3.2.5?
I dont see the actual video but I can hear it playing.
Here is the code:
-(void) viewDidLoad{
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"Facebook" ofType:#"mp4"];
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[super viewDidLoad];
}
First off – find out what video format you are having. I assume it's not the one supported by iPhones.
So when you learn this you can go ahead and look for a third party player that is able to play back your video. I'm sure there are a lot of them there. Recommendation from me – try using VLC.
If you want to use default videos app on your iPhone (which, of course, is way better than any other alternative) you can try out Windows & Mac application WALTR 2: https://softorino.com/waltr/windows-guides/how-transfer-videos-to-iphone-without-itunes. It adapts any video & music for iPhone playback and pushes them to your default app on an iPhone.
You need to set the frame for you MPMoviePlayerController and add it to your view:
theMovie.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
[self.view addSubview:theMovie.view];