简体   繁体   English

为什么视频无法在iPhone中的MPMoviePlayer上播放

[英]Why Video plays without sound on MPMoviePlayer in iPhone

I am using MPMoviePlayer to play local video files in my app. 我正在使用MPMoviePlayer在我的应用程序中播放本地视频文件。 Files are .mov formated. 文件采用.mov格式。 When I run my app in simulator it works fine. 当我在模拟器中运行我的应用程序时,它运行正常。 But when I run it in iPhone video runs with no sound. 但是当我在iPhone上运行它时,视频却没有声音。 Here is my code, 这是我的代码,

    self.currUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Gun_Shot" ofType:@"mov"]];
    if (self.mpc)
     {
       [self.mpc release];
       self.mpc = nil;
     }
    self.mpc =  [[MPMoviePlayerController alloc]
             initWithContentURL:self.currUrl];   
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.mpc];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.mpc];   
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidEnterFullScreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:self.mpc];    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:self.mpc]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackNowPlayingContinues:) name:MPMoviePlayerNowPlayingMovieDidChangeNotification object:self.mpc];  
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.mpc];

    self.mpc.controlStyle = MPMovieControlStyleNone;
    self.mpc.shouldAutoplay = NO;
    self.mpc.view.frame = CGRectMake(0, 0, self.mpView.frame.size.width, self.mpView.frame.size.height);
    [self.mpView addSubview:self.mpc.view];
    [self.mpView bringSubviewToFront:self.topMainView];
    [self.mpView bringSubviewToFront:self.bottomMainView];
    [self.mpc prepareToPlay];
    self.timeLbl.text = [NSString stringWithFormat:@"%f Sec(s)", self.mpc.duration];

I don't understand why the videos gone mute when the app runs on iPhone. 我不明白为什么该应用在iPhone上运行时视频会静音。 Any help will be appreciated.. 任何帮助将不胜感激..

Without looking at your code. 无需查看您的代码。 One reason could be that your iPhone is in silent mode. 原因之一可能是您的iPhone处于静音模式。

This answer might also help you. 这个答案可能也对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM