Mpmovieviewcontroller does not show audio control (I can listen it too !)

Source: Internet
Author: User
Hello,
I wocould 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) [[nsicationicationcenter defaultcenter] add Observer: Self selector: @ selector (movieplayerloadstatechanged :) name: jsonobject: 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]; // Ro Tate 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 Resp Ondstoselector: @ 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. [[nsicationcenter center defacenter center] addobserver: Self selector: @ selector (moviepreloaddidfinish :) name: mpmoviepla Yercontentpreloaddidfinishnotification object: Nil];} // register to receive a notification when the movie has finished playing. [[nsicationcenter center defacenter center] addobserver: Self selector: @ selector (movieplaybackdidfinish :) name: mpmovieplayerplaybackdidfinishnotification object: Nil];}/* required * for 3.2 and 4.x devices * for 3. 1.x devices see moviepreloaddidfinish: * devices */-(void) movieplayerloadstatechanged :( nsnotification *) Notification {// unless State is unknown, start playback if ([MP loadstate]! = Mpmovieloadstateunknown) {// remove observer [[nsicationcenter center defacenter center] removeobserver: Self name: icationobject: Nil]; // when tapping movie, status bar will appear, it shows up // in portrait mode by default. set orientation to landscape [[uiapplication sharedapplication] setstatusbarorientation: incluanimated: 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];}/* optional * For 3.1.x devices * for 3.2 and 4.x see movieplayerloadstatechanged: * required */-(void) moviepreloaddidfinish :( nsnotification *) Notification {// remove observer [[nsicationicationcenter defaultcenter] removeobserver: Self name: mpmovieplayercontentpreloaddidfinishnotification object: Nil]; // play the movie [MP play];}/* prop ** prop */-(void) movieplaybackdidfinish :( nsnotification *) Notification {[[uiapplication sharedapplication] setstatusbarhidden: No]; [[uiapplication sharedapplication] setstatusbarorientation: uiinterfaceorientationportrait animated: No]; // remove observer [[nsicationicationcenter defacenter center] removeobserver: Self name: icationobject: Nil]; [self resume: yes];}

 

 

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 showould inherit the application's audio session instead of creating a new session (which wowould 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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.