13

में मैं एक दृश्य नियंत्रक में एक MPMoviePlayerController दिखाने के लिए और उपयोगकर्ता बताना चाहते हैं डिफ़ॉल्ट नियंत्रण के साथ पूर्ण स्क्रीन टॉगल, YouTube एप्लिकेशन की तरह। मैं एक नंगे हड्डियों उदाहरण में निम्न कोड का उपयोग कर रहा:MPMoviePlayerController फुलस्क्रीन मोड़ आईपैड

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.player = [[MPMoviePlayerController alloc] init]; 
    self.player.contentURL = theURL; 
    self.player.view.frame = self.viewForMovie.bounds; 
    self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    [self.viewForMovie addSubview:player.view]; 
    [self.player play]; 
} 

यह अच्छी तरह से काम करता है जब तक उपयोगकर्ता, वीडियो पूर्ण स्क्रीन बनाता डिवाइस बदलता रहता है और स्क्रीन पर टैप करता। स्टेटस बार को गलत स्थिति में दिखाया गया है, जैसा कि नीचे स्क्रीनशॉट में दिखाया गया है।

screenshot

मैं टेम्पलेट iPad के लिए टैब बार आवेदन के साथ काम कर रहा हूँ। मैंने मूवी प्लेयर दिखाने के लिए ऊपर आईडीडलोड को देखा है, दृश्य चर और XIB में एक UIView जोड़ा है।

मैं क्या गलत कर रहा हूं?

+0

मैं एक ही समस्या आ रही है की कोशिश करो। अभी भी कोई कामकाज नहीं है? – samvermette

+0

मुझे भी। किसी को यह काम मिल गया है? – V1ru8

+0

क्या आपको कोई जवाब मिला? – Jingwei

उत्तर

2

है shouldAutorotateToInterfaceOrientation: interfaceOrientation समर्थित झुकाव के सभी के लिए लौटने हाँ?

 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

यदि आपने अपना अधिक कोड प्रदान किया है तो इससे मदद मिलेगी।

+0

हां। प्रोजेक्ट में जो एकमात्र कोड जोड़ा गया है, वह दृश्य आईडीडलोड है और निश्चित रूप से XIB में ViewForMovie है। यह आईपैड के लिए डिफ़ॉल्ट टैब बार एप्लिकेशन है। – hpique

1

आप अपने यूआई के लिए इंटरफ़ेस बिल्डर का उपयोग कर रहे हैं? यदि ऐसा है तो सुनिश्चित करें कि आप दृश्य विशेषताओं निरीक्षक में दृश्य परिदृश्य को 'परिदृश्य' पर सेट करते हैं।

+0

अब यह अन्य अभिविन्यास में विफल रहता है। – hpique

1

एक ही समस्या थी, सिर्फ आधा एक दिन बिताया इसे बाहर छँटाई। पोर्ट्रेट अभिविन्यास में आईपैड के साथ, जब भी मैंने नमूना कोड (या नेट पर कोई भी पाया) का उपयोग करके एक वीडियो शुरू किया, तो वीडियो और कंट्रोल बार को पोर्ट्रेट के लिए प्रारूपित किया गया था, और इसलिए स्क्रीन पर सभी जगहें थीं।

वैसे भी, मेरे लिए निम्नलिखित काम करता है।

/* Call the code like below: 
     int iLandscape; 
     if(newOrientation==UIInterfaceOrientationLandscapeLeft || newOrientation==UIInterfaceOrientationLandscapeRight) 
      iLandscape=1; 

     [self PlayVideo:iLandscape fullscreen:1] 
    */ 
     ////////////////////////////////////////////////////////////////////////// 
     - (void)PlayVideo:(int)iLandscape fullscreen:(int)iFullScreen 
     { 
      NSString *url = [[NSBundle mainBundle] pathForResource:@"myvideofile" ofType:@"m4v"]; 

     if(iFullScreen==0) 
     { 
      MPMoviePlayerController *player2 = 
       [[MPMoviePlayerController alloc] 
        initWithContentURL:[NSURL fileURLWithPath:url]]; 

      [[NSNotificationCenter defaultCenter] 
       addObserver:self 
        selector:@selector(movieFinishedCallback:) 
         name:MPMoviePlayerPlaybackDidFinishNotification 
        object:player2]; 

      //---play partial screen--- 
      player2.view.frame = CGRectMake(0, 0, m_iScreenWidth, m_iScreenHeight); 
      [self addSubview:player2.view]; 
      //---play movie--- 
      [player2 play]; 
     } 
     else 
     { 
      MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] 
       initWithContentURL:[NSURL fileURLWithPath:url]]; 

      [[NSNotificationCenter defaultCenter] 
       addObserver:self 
        selector:@selector(movieFinishedCallback:) 
         name:MPMoviePlayerPlaybackDidFinishNotification 
        object:[playerViewController moviePlayer]]; 

      if(iLandscape) 
      { 
       playerViewController.view.frame = CGRectMake(0, 0, m_iScreenWidth, m_iScreenHeight); 
      } 
      [self addSubview:playerViewController.view]; 
      //play movie 
      MPMoviePlayerController *player = [playerViewController moviePlayer]; 
      player.scalingMode=MPMovieScalingModeAspectFit; 
      [player play]; 
     } 
    } 


    ////////////////////////////////////////////////////////////////////////// 
    - (void) movieFinishedCallback:(NSNotification*) aNotification 
    { 
     MPMoviePlayerController *player = [aNotification object]; 
     [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];  
     [player autorelease];  
     [player.view removeFromSuperview]; 
    } 
0

क्या आपने इस समस्या को हल किया?

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

यह कोड आपकी मदद कर सकता है।

3

हाँ, मुझे भी इस समस्या का सामना करना पड़ रहा है। यह निश्चित रूप से MPMoviePlayerController में एक बग प्रतीत होता है।

वैकल्पिक हल मैं अपने आवेदन में पर बसे किया है, उसे स्थिति अपने आप को बार सही करने के लिए जब मैं पूर्ण स्क्रीन मोड से बाहर निकलें है:

- (void)playerDidExitFullscreen:(NSNotification *)notification { 
    MPMoviePlayerController *moviePlayer = (MPMoviePlayerController *) notification.object; 

    if (moviePlayer == self.player) { 
     UIApplication *app = [UIApplication sharedApplication]; 
     if (app.statusBarOrientation != self.interfaceOrientation) { 
      [app setStatusBarOrientation:self.interfaceOrientation animated:NO]; 
     } 
    } 
} 

यह समस्या हल नहीं होती पूर्ण-स्क्रीन मोड में है, लेकिन यह करता है इसे बाद में ठीक करें।

निश्चित रूप से नोट समारोह की जरूरत है कि अधिसूचना में शामिल होना:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil]; 
0

यह मिला।

एक ही समस्या थी - यहां मैंने जो किया है। मैं यह सुझाव दूंगा कि यह आपके काम में एक-एक करके कोड को जोड़ने का सुझाव देगा कि यह कैसे काम करता है।

पहला - मैंने चीजें पोर्ट्रेट मोड रखी हैं।

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

तब मैंने फिल्म को स्टेटस बार पर ले जाया।नोट - यह मान लिया गया वीडियो फिर एक 4x3 पहलू अनुपात

theVideo = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath : path]]; 
float aspectRatio = (3.0f/4.0f); 
float theMovieHeight = [self view].bounds.size.width * aspectRatio; 
[[theVideo view] setFrame:(CGRectMake(0, [self view].bounds.size.height - theMovieHeight, [self view].bounds.size.width, theMovieHeight))]; 

है, वह जगह है जहां आवेदन शुरू होता है में (मेरी परियोजना में, यह didFinishLaunchingWithOptions समारोह में है) - वैसे भी, तुम बस के लिए उपयोग की जरूरत है खिड़की वस्तु।

float aspectRatio = (3.0f/4.0f); 
float theMovieHeight = self.window.bounds.size.width * aspectRatio; 
float theSpaceAboveTheMovie = self.window.bounds.size.height - theMovieHeight; 
float whereTheMovieShouldBeCentered = (self.window.bounds.size.height - theMovieHeight)/2; 

CGAffineTransform theTransform = CGAffineTransformMakeTranslation(0,0); 

theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

[self.window setTransform:theTransform]; 

याद रखें कि एफ़िन ट्रांसफॉर्म रिवर्स ऑर्डर में किए जाते हैं। तो अगर आप प्रत्येक क्या बदलना है (मैं सुझाव है कि आप चाहिए) कर देखना चाहते हैं, पहले तीन

यहाँ आप फिल्म और स्थिति पट्टी

// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
// theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
// theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
    theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

तो पेज पर केंद्रित देखना चाहिए पहले बाहर टिप्पणी दो

यहाँ आप देखना चाहिए फिल्म और स्थिति पट्टी घुमाया और अब केंद्रित

// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
// theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
    theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
    theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

यहाँ आप यह घुमाया देखना चाहिए और केंद्रित

// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
    theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
    theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
    theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

और उन सब के साथ, यह घुमाया और फुलस्क्रीन

तुम मेरे नमूना कोड here डाउनलोड कर सकते हैं है।

0

इस

- (void)willEnterFullscreen:(NSNotification*)notification { 
    NSLog(@"willEnterFullscreen"); 

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

- (void)enteredFullscreen:(NSNotification*)notification { 
    NSLog(@"enteredFullscreen"); 
} 

- (void)willExitFullscreen:(NSNotification*)notification { 
    NSLog(@"willExitFullscreen"); 

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


} 

- (void)exitedFullscreen:(NSNotification*)notification { 
    NSLog(@"exitedFullscreen"); 

    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
} 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^