MPMoviePlayerController showing black screen with sound in iOS 7, works fine in iOS 6

ⅰ亾dé卋堺 提交于 2020-01-13 11:04:41

问题


//introVideoViewController

#import <AVFoundation/AVAudioSession.h>
#import <AudioToolbox/AudioServices.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <MediaPlayer/MediaPlayer.h>
@property(nonatomic,strong) MPMoviePlayerController *playercontroller;

Hi Guys,

anybody know what in iOS 7 i can heard my video sound but not the video, it works fine in iOS 6.

any comments are greatly appreciated.

//introVideoViewController

//prepare & init video
-(void)prepareIntroVideo
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"intro_movie" ofType:@"mp4"]];
    //NSURL *url = [NSURL URLWithString:@"http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov"];
    self.playercontroller = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.playercontroller.view setFrame:CGRectMake(0, 0, 320,480)];
    self.playercontroller.movieSourceType = MPMovieSourceTypeFile;
    self.playercontroller.scalingMode = MPMovieScalingModeAspectFill;
    self.playercontroller.fullscreen = YES;
    self.playercontroller.controlStyle = MPMovieControlStyleNone;
    //playercontroller.controlStyle = MPMovieControlStyleFullscreen;
    self.playercontroller.view.userInteractionEnabled =NO;
    self.playercontroller.view.backgroundColor = [UIColor blackColor];
    self.playercontroller.shouldAutoplay = NO;

    //playercontroller.repeatMode = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:self.playercontroller];
    [self.playercontroller prepareToPlay];
    [self.view addSubview:self.playercontroller.view];


    // get the handle


    // Get the result
    self.firstlaunchVideoCheck = [self.defaults stringForKey:@"firstlaunchVideo"];

    //NSLog(@"first launch null or 1 = %@",firstlaunchVideoCheck);


    if ([self.firstlaunchVideoCheck intValue])
    {
        //skip view overlay
        UIView *skipView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
        UITapGestureRecognizer *singleTapping =
        [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showSkipButton)];
        singleTapping.delegate =self;
        singleTapping.numberOfTapsRequired = 1;
        [skipView addGestureRecognizer:singleTapping];

        singleTapping.cancelsTouchesInView = NO;

        //skipbutton
        self.skipMovieButton = [UIButton buttonWithType:UIButtonTypeCustom];
        //0, 276, 480, 54)

        if (isPhone568)
        {
         [self.skipMovieButton setFrame:CGRectMake(227, 504, 92, 44)];
        }
        else
        {
            [self.skipMovieButton setFrame:CGRectMake(227, 436, 92, 44)];
        }

        [self.skipMovieButton setBackgroundColor:[UIColor clearColor]];

        UIImage *skipMovieButtonNormal = [UIImage imageNamed:@"button_skip.png"];
        //UIImage *skipMovieButtonPress = [UIImage imageNamed:@"skip-(active).png"];

        [self.skipMovieButton setBackgroundImage:skipMovieButtonNormal forState:UIControlStateNormal];
        //[self.skipMovieButton setBackgroundImage:skipMovieButtonPress forState:UIControlStateHighlighted];
        [self.skipMovieButton addTarget:self action:@selector(skipMovie) forControlEvents:UIControlEventTouchUpInside];
        [skipView addSubview:self.skipMovieButton];
        [self.view addSubview:skipView];
    }
    [self.playercontroller stop];

    [self.view bringSubviewToFront:self.titleImgView];
    [self.view bringSubviewToFront:self.startMovieButton];
    [self.view sendSubviewToBack:self.playercontroller.view];
    [self.view sendSubviewToBack:self.skipMovieButton];
}

//play video
-(void)playIntroVideo
{
    NSLog(@"self.playercontroller.playbackState %i",self.playercontroller.playbackState);
    if (self.playercontroller.playbackState == MPMoviePlaybackStatePlaying)
    {
        NSLog(@"playerconroller playing, do nothing");
    }
    else if (self.playercontroller.playbackState == MPMoviePlaybackStateStopped)
    {
        NSLog(@"playerconroller playing, do nothing11111111111");
        [self.playercontroller play];
    }
}


//called when video played completed
- (void)moviePlaybackComplete:(NSNotification *)notification
{
    ////NSLog(@"Here Got Called");

    MPMoviePlayerController *moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayerController];
    //[playercontroller.view removeFromSuperview];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIApplicationDidEnterBackgroundNotification
                                                  object:[UIApplication sharedApplication]];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIApplicationWillEnterForegroundNotification
                                                  object:[UIApplication sharedApplication]];





   if (![self.firstlaunchVideoCheck intValue])
   {
       self.firstlaunchVideoCheck = @"1";
        // get the handle
       [self.defaults setObject:self.firstlaunchVideoCheck forKey:@"firstlaunchVideo"];

        // save it
       [self.defaults synchronize];
    }

    [self skipMovie];
}

回答1:


all works fine after adding one more line.

self.playercontroller.contentURL = url;


来源:https://stackoverflow.com/questions/18971961/mpmovieplayercontroller-showing-black-screen-with-sound-in-ios-7-works-fine-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!