MPMoviePlayer 声音在模拟器和 ipad 设备中工作,但在 iPhone 设备中不工作

发布于 2025-01-07 22:10:55 字数 947 浏览 0 评论 0 原文

我的 MPMoviePlayerController 有问题,即我正在以(m3u8 格式)MPMoviePlayer 播放实时流 url,如下所示

player = [[MPMoviePlayerController alloc] initWithContentURL:audioUrl];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(loadStateDidChange:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:player];
        if ([player respondsToSelector:@selector(loadState)]) 
        {
            // Set movie player layout

            [player setMovieSourceType:MPMovieSourceTypeStreaming];
            [player setControlStyle:MPMovieControlModeVolumeOnly];
            [player setFullscreen:YES];
            [player prepareToPlay];
            [player play];

        }
    }

: iPad 设备装有 ios 5 版本,但我拥有的任何 iPhone 设备都无法提供音频。

请帮帮我... 提前致谢。

I have a problem with MPMoviePlayerController, i.e. I am playing the live stream url in (m3u8 format) MPMoviePlayer like below:

player = [[MPMoviePlayerController alloc] initWithContentURL:audioUrl];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(loadStateDidChange:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:player];
        if ([player respondsToSelector:@selector(loadState)]) 
        {
            // Set movie player layout

            [player setMovieSourceType:MPMovieSourceTypeStreaming];
            [player setControlStyle:MPMovieControlModeVolumeOnly];
            [player setFullscreen:YES];
            [player prepareToPlay];
            [player play];

        }
    }

It is working in both simulators & iPad device with ios 5 version, but it is not giving the audio in any iPhone device i have.

Please help me out...
Thanks, in advance.

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

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

发布评论

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

评论(4

回眸一遍 2025-01-14 22:10:55

simham 先生...检查下面的网址,它对我们有帮助 becoZ

  1. 在移动 safari 中调用流网址。如果结果相同,则您的代码是正确的,而流则不正确。那么这将是一个编码错误的音频流。

  2. 这也取决于带宽,也低于参考网址关于带宽检查一次....您的参考流URL准备,根据BandWith

参考 URL:

mr simham ... check this below url it help for us becoZ

  1. Call stream-url within mobile safari. If that has the same results, then your code is correct and the stream is not. It would be an incorrectly encoded audio stream then.

  2. it depends on bandwidth also below ref url regards to bandwidth check it once.... u r ref Stream URL prepare,according to BandWith

REFERENCE URL:

思念绕指尖 2025-01-14 22:10:55

您正在为需要 MPMovieControlStylecontrolStyle 属性分配已弃用的 MPMovieControlMode (MPMovieControlModeVolumeOnly)。

此外,您的代码缺少将 MPMoviePlayerController.view 分配给任何超级视图的部分,并且其大小也丢失。

最后但我想对你来说最重要的是,我猜你正在尝试的 iPhone 已经将音量一直调到静音。或者,音频路由可能未设置为扬声器输出。对于后者,请确保您没有在应用程序的其他任何地方错误地设置音频会话。如有疑问,请尝试摆弄 useApplicationAudioSession 属性。尝试将其设置为NO,看看这是否会改变您的结果。

如果上述所有操作均失败,则另一项检查将是在 mobile safari 中调用stream-url。如果结果相同,则您的代码是正确的,而流则不正确。那么这将是一个编码错误的音频流。

You are assigning a deprecated MPMovieControlMode (MPMovieControlModeVolumeOnly) towards the controlStyle property which is expecting a MPMovieControlStyle.

Additionally, your code is missing the part that assigns the MPMoviePlayerController.view towards any superview and also its sizing is missing.

Last but I guess most importantly for you, I am guessing that the iPhone you are trying it with has set the volume all the way down to silence. Or, maybe the audio-routing is not set towards speaker-output. For the latter, make sure you are not setting up the audio session incorrectly anywhere else in your App. When in doubt, try fiddling with the useApplicationAudioSession property. Try setting it towards NO and see if that changes your results.

If all above fails, then one additional check would be to call the stream-url within mobile safari. If that has the same results, then your code is correct and the stream is not. It would be an incorrectly encoded audio stream then.

满意归宿 2025-01-14 22:10:55

检查您的 iPhone 是否处于扬声器模式 -

如果没有,请使用此设置 -

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

Check if your iPhone is on loudspeaker mode or not -

if not than set it using this-

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
司马昭之心 2025-01-14 22:10:55

检查 iPhone 是否处于静音模式。要在静音模式下也播放音频,请在 AppDelegate 的 中添加以下代码 application:didFinishLaunchingWithOptions:

NSError *setCategoryErr = nil;
NSError *activationErr  = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

Check if the iPhone is in silent mode. To play audio even in silent mode, add the following code in AppDelegate's application:didFinishLaunchingWithOptions:

NSError *setCategoryErr = nil;
NSError *activationErr  = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文