Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-04-2010, 06:18 AM   #1 (permalink)
Registered Member
 
malcom's Avatar
 
Join Date: Aug 2008
Posts: 29
malcom is on a distinguished road
Send a message via AIM to malcom
Default MPMovieViewController does not show audio control (I can listen it too!)

Hello,
I would to play a video file in my iphone. Everything works fine but the result video does not show the volume control (I can listen audio!).
What's wrong?



This is the code (an example project is here: http://dl.dropbox.com/u/103260/MoviePlayer-ios4.zip):

Any idea?
Code:
@implementation CSMoviePlayer



- (id) initWithMovieAtPath:(NSURL *) path

{

     self = [super init];

     if (self != nil) {

          inPlay = NO;

          movieURL = [path retain];

          NSLog(@"LOAD MOVIE %@",[movieURL absoluteString]);

          [self.view setBackgroundColor:[UIColor blackColor]];

          

          

     }

     return self;

}







// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

    [super viewDidLoad];

     // Register that the load state changed (movie is ready)

     [[NSNotificationCenter defaultCenter] addObserver:self 

                                                        selector:@selector(moviePlayerLoadStateChanged:) 

                                                             name:MPMoviePlayerLoadStateDidChangeNotification 

                                                          object:nil];

}



- (void) viewDidAppear:(BOOL)animated {

     

          // When tapping movie, status bar will appear, it shows up

          // in portrait mode by default. Set orientation to landscape

     [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

     

          // Rotate the view for landscape playback

     [[self view] setBounds:CGRectMake(0, 0, 480, 320)];

     [[self view] setCenter:CGPointMake(160, 240)];

     [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

          [self readyPlayer];



}



- (void) readyPlayer

{

     [[MCHTTPFetcher httpCentral] networkActivityIncrement:YES];



     inPlay = YES;

      mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

     

     if ([mp respondsToSelector:@selector(loadState)]) 

     {

               // Set movie player layout

          [mp setControlStyle:MPMovieControlStyleFullscreen];

          [mp setFullscreen:YES];

          

               // May help to reduce latency

          [mp prepareToPlay];

          

     

     }  

     else

     {

               // Register to receive a notification when the movie is in memory and ready to play.

          [[NSNotificationCenter defaultCenter] addObserver:self 

                                                             selector:@selector(moviePreloadDidFinish:) 

                                                                  name:MPMoviePlayerContentPreloadDidFinishNotification 

                                                               object:nil];

     }

     

          // Register to receive a notification when the movie has finished playing. 

     [[NSNotificationCenter defaultCenter] addObserver:self 

                                                        selector:@selector(moviePlayBackDidFinish:) 

                                                             name:MPMoviePlayerPlaybackDidFinishNotification 

                                                          object:nil];

}



/*---------------------------------------------------------------------------

 * For 3.2 and 4.x devices

 * For 3.1.x devices see moviePreloadDidFinish:

 *--------------------------------------------------------------------------*/

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 

{



          // Unless state is unknown, start playback

     if ([mp loadState] != MPMovieLoadStateUnknown)

     {

               // Remove observer

          [[NSNotificationCenter      defaultCenter] 

           removeObserver:self

           name:MPMoviePlayerLoadStateDidChangeNotification 

           object:nil];

          

               // When tapping movie, status bar will appear, it shows up

               // in portrait mode by default. Set orientation to landscape

          [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

          

               // Rotate the view for landscape playback

          [[self view] setBounds:CGRectMake(0, 0, 480, 320)];

          [[self view] setCenter:CGPointMake(160, 240)];

          [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

     

               // Set frame of movieplayer

          [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];

          

               // Add movie player as subview

          [[self view] addSubview:[mp view]];   

          

               // Play the movie

          [mp play];

     }

}



/*---------------------------------------------------------------------------

 * For 3.1.x devices

 * For 3.2 and 4.x see moviePlayerLoadStateChanged: 

 *--------------------------------------------------------------------------*/

- (void) moviePreloadDidFinish:(NSNotification*)notification 

{

          // Remove observer

     [[NSNotificationCenter      defaultCenter] 

      removeObserver:self

      name:MPMoviePlayerContentPreloadDidFinishNotification

      object:nil];

     

          // Play the movie

      [mp play];

}



/*---------------------------------------------------------------------------

 * 

 *--------------------------------------------------------------------------*/

- (void) moviePlayBackDidFinish:(NSNotification*)notification 

{    

     [[UIApplication sharedApplication] setStatusBarHidden:NO];

     [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];



          // Remove observer

     [[NSNotificationCenter      defaultCenter] 

      removeObserver:self

      name:MPMoviePlayerPlaybackDidFinishNotification 

      object:nil];

     

     [self dismissModalViewControllerAnimated:YES];     

}
malcom is offline   Reply With Quote
Old 09-04-2010, 07:27 AM   #2 (permalink)
Registered Member
 
malcom's Avatar
 
Join Date: Aug 2008
Posts: 29
malcom is on a distinguished road
Send a message via AIM to malcom
Default

I think I've solved.
Without audio enabled (iphone audio hardware switch is off) audio controller disappear.
It will appear only when hw is on.
This because the audio inherit the application's audio session.
Using:
Code:
// Indicates if the movie player should inherit the application's audio session instead of creating a new session (which would interrupt the application's session).
// Defaults to YES. Setting this property during playback will not take effect until playback is stopped and started again.

mp.useApplicationAudioSession = NO;
Audio controller appear every time and it's indipendent from the switch.
The only question is...why on simulator it's always off?
malcom is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 343
11 members and 332 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, iram91419, linkmx, nadav@webtview.com, Objective Zero, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:45 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0