简体   繁体   中英

Why Video plays without sound on MPMoviePlayer in iPhone

I am using MPMoviePlayer to play local video files in my app. Files are .mov formated. When I run my app in simulator it works fine. But when I run it in iPhone video runs with no sound. 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. Any help will be appreciated..

Without looking at your code. One reason could be that your iPhone is in silent mode.

This answer might also help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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