2012-08-23 6 views
8

के साथ वीडियो नहीं चला सकता है मैंने निम्नलिखित ViewController.m के साथ एक नई परियोजना बनाई है। जब मैं ऐप चलाता हूं तो मैं अपेक्षित मूल/आकार (38, 100, 250, 163) का एक बॉक्स देख सकता हूं लेकिन यह काला है और कोई वीडियो नहीं चल रहा है। वहाँ Xcode में एक अजीब उत्पादन होता है:MPMoviePlayerViewController

2012-08-23 15:36:45.559 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay for pause 
2012-08-23 15:36:45.560 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay 
2012-08-23 15:37:18.186 VideoTest1[11398:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0) 

ध्यान दें कि वीडियो Videora iPhone कनवर्टर के साथ बदला है और Xcode में ठीक खेलता है (इसलिए यह एक वीडियो समस्या नहीं है) है; वीडियो का मार्ग ठीक है क्योंकि जब मैं डेमो-आईफोन 1 निर्दिष्ट करता हूं (जो अस्तित्व में नहीं है) मुझे शून्य अपवाद मिलता है। मैंने सिम्युलेटर और आईफोन पर कोशिश की: हमेशा ब्लैक बॉक्स। कोई विचार?

#import "ViewController.h" 
#import <MediaPlayer/MediaPlayer.h> 

@interface ViewController() 

@end 

@implementation ViewController 
- (void)moviePlaybackComplete:(NSNotification *)notification 
{ 
    MPMoviePlayerController *moviePlayerController = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:moviePlayerController]; 

    [moviePlayerController.view removeFromSuperview]; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"]; 
    NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlaybackComplete:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:moviePlayerController]; 
    [moviePlayerController.view setFrame:CGRectMake(38, 
                100, 
                250, 
                163)]; 
    [self.view addSubview:moviePlayerController.view]; 
    [moviePlayerController play]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

@end 
+0

क्या आपने किसी अन्य वीडियो के साथ प्रयास किया है। शायद एक mp4 vimeo से डाउनलोड किया? –

+0

स्टीव, वीडियो वास्तव में ठीक है क्योंकि यह मेरे दूसरे ऐप में बिल्कुल उसी कोड के साथ खेलता है। लेकिन अभी भी अंतर नहीं पता कर सकते हैं। बीटीडब्ल्यू मैंने एक्सकोड आउटपुट जोड़ा। शायद यह आपको कुछ विचार देगा कि यह समस्या क्या है। – maxgrinev

उत्तर

3

मैं playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

+0

+1: इससे मेरी मदद की .... धन्यवाद एक टन ... –

2

आप एआरसी का उपयोग करते हैं जोड़कर एक समान समस्या का समाधान? यदि ऐसा है तो आपको MPMoviePlayerController को बनाए रखना होगा!

viewDidLoad

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"]; 
    NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlaybackComplete:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:moviePlayerController]; 
    [moviePlayerController.view setFrame:CGRectMake(38, 
               100, 
               250, 
               163)]; 
    [self.view addSubview:moviePlayerController.view]; 
    [moviePlayerController play]; 
    [self setController:moviePlayerController]; 
} 
+0

+1 बनाए रखने के लिए +1। बहुत सारे ट्यूटोरियल अस्थायी चर के उपयोग को दिखाते हैं। – DanneManne

13

की अंतिम पंक्ति अपने इंटरफेस को यह जोड़े

@property (nonatomic, strong) MPMoviePlayerController *controller; 

चेक मैं सिर्फ कोड की इस पंक्ति के साथ एक समान समस्या हल हो। खिलाड़ी नियंत्रकों अब पता चलता है और वीडियो पूरी तरह से खेलता है:

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer; 
// 
@synthesize moviePlayer = _moviePlayer; 
// 
[self.moviePlayer prepareToPlay]; 

संशोधित अपने वातावरण के अनुरूप हों।

+2

आईपैड/आईओएस 6 पर "readyToplay" को कॉल करने के लिए यह मेरे लिए तय किया गया है। इसके बिना, "MPMoviePlayerLoadStateDidChangeNotification" नहीं भेजा जा रहा था क्योंकि खिलाड़ी वीडियो को प्रीलोड करने के लिए परेशान नहीं था। – diachedelic

+1

आईओएस 6 पर ब्लैक स्क्रीन होने से पहले (आईओएस 5 और नीचे ठीक काम करते समय) मेरे लिए भी इसे फिक्स्ड किया गया। – Dado

+0

यह मेरी समस्या को ठीक करता है, हालांकि, 5 सेकंड के भीतर एक splitView से एक और वीडियो लोड करते समय, मैं अभी भी पिछले वीडियो से ऑडियो सुन सकता हूं जब तक कि 5 सेकंड ऊपर न हो ... किसी को भी यह समस्या है? मैं AVFoundation ढांचे को जोड़ने के बारे में सोच रहा हूं ताकि मैं ऑडियो सत्रों को आजमा सकूं और नियंत्रित कर सकूं? – whyoz

-2

वीडियो प्रारूप भी देखें। मैं इस त्रुटि को अपने नमूना वीडियो .m4v (जिसे मैंने ऐप्पल की वेबसाइट से डाउनलोड किया) के साथ प्राप्त किया। आखिर में मैंने इसे एक अलग वीडियो क्लिप के साथ आजमाया जो .mp4 था और यह ठीक काम करता था। कई कंसोल अभी भी मेरे कंसोल पर आ गए हैं।

2013-01-22 15:44:04.850 VideoTesting[4497:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0 
2013-01-22 15:44:04.851 VideoTesting[4497:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up. 
2013-01-22 15:44:04.853 VideoTesting[4497:c07] [MPAVController] Autoplay: Disabling autoplay for pause 
2013-01-22 15:44:04.853 VideoTesting[4497:c07] [MPAVController] Autoplay: Disabling autoplay 
2013-01-22 15:44:04.861 VideoTesting[4497:c07] [MPAVController] Autoplay: Enabling autoplay 

हालांकि वीडियो अभी भी खेला गया है।

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