首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在静音模式下播放电影的音频吗?

在静音模式下播放电影的音频吗?
EN

Stack Overflow用户
提问于 2012-07-18 02:52:56
回答 1查看 778关注 0票数 0

很抱歉我的问题,但我已经实现了一个介绍视频,尽管我的iPad的硬件静音开关,音频正在播放。我还在我的应用程序中使用AVAudioplayer,只是为了播放简短的声音样本。在这个类中,它是我设置"AVAudioSessionCategory“的唯一区域。但是对于所有的音频播放,没有什么可听的。这只是我的介绍视频。

有什么帮助吗?如何修复“音频错误”,使电影播放器是静音的?谢谢你

这是我的音频类:

代码语言:javascript
复制
- (id)initWithSoundfileName:(NSString*) file 
{
    if ((self = [super init]))
    {
        NSString* filename =       [file stringByDeletingPathExtension];
        NSString* fileextension =  [file pathExtension];

        // get file path from bundle
        NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: filename ofType: fileextension];
        NSLog(@"AudioPlayer init: %@", soundFilePath);

        NSURL* fileurl = [[NSURL alloc] initFileURLWithPath:soundFilePath];
        NSError* error = nil;

        AVAudioPlayer* audioplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileurl error:&error ];
        if (error) { NSLog(@"Error creating AVAudioPlayer %@", [error description]);}

        // set audio policy
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];

        self.player =  audioplayer;
        [self.player prepareToPlay];
        [self.player setDelegate:self];
    }
    return self;

}
-(void) play{
    [self.player play];
}

下面是我的视频回放方法:

代码语言:javascript
复制
- (void)playIntroVideo
{    
    NSString *movpath = [[NSBundle mainBundle] pathForResource:@"mymovie" ofType:@"mp4"];

    NSURL *fileURL    =   [NSURL fileURLWithPath:movpath];  
    self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
    self.moviePlayerController.fullscreen = YES;
    self.moviePlayerController.scalingMode = MPMovieScalingModeAspectFit;
    self.moviePlayerController.controlStyle = MPMovieControlStyleNone;
    self.moviePlayerController.movieSourceType = MPMovieSourceTypeFile;

    self.moviePlayerController.useApplicationAudioSession = NO;     
    [self.moviePlayerController.view setFrame: self.view.bounds];   

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackComplete:)  
                                                 name:MPMoviePlayerPlaybackDidFinishNotification  
                                               object:self.moviePlayerController];  


    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackStateChanged:)  
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification  
                                               object:self.moviePlayerController];  

    [self.view addSubview:self.moviePlayerController.view];

    [self.moviePlayerController prepareToPlay];
    [self.moviePlayerController play];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-18 05:12:46

就像@Till提到的那样:当我将MoviePlayerController属性更改为useApplicationAudioSession=TRUE时,它会修复我的问题。音频播放处于静默状态。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11528986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档