搜尋此網誌

2012年9月17日 星期一

在使用模擬器時有聲音,但裝到ios device卻沒聲音




MPMoviePlayer sound working in Simulators and ipad device, but not Working in iPhone Device


http://stackoverflow.com/questions/9408211/mpmovieplayer-sound-working-in-simulators-and-ipad-device-but-not-working-in-ip

http://stackoverflow.com/questions/5867341/how-to-turn-off-audio-in-mpmovieplayercontroller-iphone

主要就是針對下面設定成NO




useApplicationAudioSession




ex:- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.
    [loadFilmIndicatorView startAnimating];
    //設定影片檔路徑
    MyManager *sharedManager = [MyManager sharedManager];
    
    NSURL *url = [NSURL URLWithString:sharedManager.playFilmUrl];
   // NSString *path = [[NSBundle mainBundle] pathForResource:@"Keep in touch" ofType:@"mp4"];
   // url=[NSURL fileURLWithPath:path];
    
    //playerMPMoviePlayerController型態的指標
    player = [[MPMoviePlayerController alloc] initWithContentURL:url];
    
    //旋轉90
    player.view.transform = CGAffineTransformMakeRotation(1.5707964);
    
    //設定影片比例的縮放、重複、控制列等參數
    player.scalingMode = MPMovieScalingModeAspectFit;
    player.repeatMode = MPMovieRepeatModeNone;
    player.controlStyle = MPMovieControlStyleFullscreen;//MPMovieControlStyleDefault;
    player.useApplicationAudioSession=NO;
    //使用Observer製作完成播放時要執行的動作
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:player];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
    
    //自動縮放符合畫面比例
    // player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    NSLog(@"filmurl:%@",sharedManager.playFilmUrl);
    
    [player play];
  
}

沒有留言:

張貼留言