在使用 MPMoviePlayerController 的某些设备上仅通过耳机播放声音

发布于 2025-01-03 20:16:10 字数 2002 浏览 6 评论 0原文

我有一个奇怪的问题要问大家。

MPMoviePlayerController 正在正常播放视频,并且音频仅通过耳机播放。

真正的问题是,这种情况只发生在某些 iPad 和 iPhone 上,即使是相同的型号 运行完全相同的系统!

我在这里创建了一个简单的失败示例:

http://www.porcaro.org/MPMoviePlayerController/TestMovie .zip

我见过它在 iPhone 4S、iPhone 4 和 iPad 2 上运行良好但失败。

这是最相关的代码。感谢您的任何见解,我还将向 Apple 提交一个错误:

(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];


    moviePath = [NSString stringWithFormat:@"%@/intro.m4v", [[NSBundle mainBundle] bundlePath]];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    theMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    controlStyle = MPMovieControlStyleEmbedded;
    movieView = [self view];
    movieRect = [[self view] frame];
    controlStyle = MPMovieControlStyleFullscreen;

    theMoviePlayer.controlStyle = controlStyle;
    theMoviePlayer.view.userInteractionEnabled = YES;

    if (1) {
        NSLog(@"Created theMoviePlayer: %@.  Playing: %@", theMoviePlayer, moviePath);
    }

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(checkForEndOfMovie:)
                                          name:MPMoviePlayerPlaybackStateDidChangeNotification
                                          object:theMoviePlayer];

    // this line doesn't fix the problem                                                                                                       
    //[theMoviePlayer prepareToPlay];                                                                                                          
    [[theMoviePlayer view] setFrame:movieRect];
    [movieView addSubview: [theMoviePlayer view]];
    [theMoviePlayer play];
}

I have a weird problem for you all.

MPMoviePlayerController is playing the video fine, and the audio ONLY plays through headphones.

The real drag is that this only happens on some iPads and iPhones, even the SAME EXACT MODELS
running the SAME EXACT SYSTEM!

I've created a simple failing example here:

http://www.porcaro.org/MPMoviePlayerController/TestMovie.zip

I've seen it run fine and fail on iPhone 4S, iPhone 4 and iPad 2.

Here is the most relevant code. Thanks for any insight, I'm going to submit a bug to Apple as well:

(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];


    moviePath = [NSString stringWithFormat:@"%@/intro.m4v", [[NSBundle mainBundle] bundlePath]];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    theMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    controlStyle = MPMovieControlStyleEmbedded;
    movieView = [self view];
    movieRect = [[self view] frame];
    controlStyle = MPMovieControlStyleFullscreen;

    theMoviePlayer.controlStyle = controlStyle;
    theMoviePlayer.view.userInteractionEnabled = YES;

    if (1) {
        NSLog(@"Created theMoviePlayer: %@.  Playing: %@", theMoviePlayer, moviePath);
    }

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(checkForEndOfMovie:)
                                          name:MPMoviePlayerPlaybackStateDidChangeNotification
                                          object:theMoviePlayer];

    // this line doesn't fix the problem                                                                                                       
    //[theMoviePlayer prepareToPlay];                                                                                                          
    [[theMoviePlayer view] setFrame:movieRect];
    [movieView addSubview: [theMoviePlayer view]];
    [theMoviePlayer play];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过期情话 2025-01-10 20:16:10

这是一个老问题,但也许会对某人有所帮助。我遇到了同样的问题,发现只有当手机处于静音模式时才会发生这种情况。

解决方案是将播放器的 useApplicationAudioSession 属性设置为 false。

[theMoviePlayer setUseApplicationAudioSession:NO];

This is an old question but maybe it'll help someone. I came across the same issue and found out it was happening when the phone is in silent mode only.

Solution is to set the player's useApplicationAudioSession property to false.

[theMoviePlayer setUseApplicationAudioSession:NO];
〆一缕阳光ご 2025-01-10 20:16:10

当我使用 mpMoviePlayer 在 iPad 2 上播放视频时,就出现了这个问题。视频播放完美,但只有连接耳机时才会出现音频。

解决问题的方案:

[theMoviePlayer setUseApplicationAudioSession:NO];

This problem was happen to me once playing video on iPad 2 using mpMoviePlayer. The video was playing perfectly but audio only comes when earphones connected.

Solution to solve the problem:

[theMoviePlayer setUseApplicationAudioSession:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文