使用 MPMoviePlayerViewController 播放音频

发布于 2024-11-28 06:55:57 字数 1052 浏览 0 评论 0原文

参考 iOS TabController 应用程序...

Apple 文档声明 AVAudioPlayer 类不提供对基于 HTTP URL 的流音频的支持。 AVAudioPlayer 仅播放 iApp 中嵌入的音乐(以 file:// 作为 url)。

鉴于此,我确实使用 MPMoviePlayerViewController 来播放它可以处理的这些网络存储的音频/mp3 文件。

这绝对有效。我从带有歌曲歌词的 UIView 开始。在这个 UIView 的最底部是一个“播放”按钮。用户点击此按钮即可播放音频/mp3;但是,音频/QuickTime (( Q )) 图形会出现在前台,歌词会消失,直到用户点击“完成”为止。我想要发生的是音频/mp3 在后台播放,歌词保留在前面。

顺便说一句,我真的不需要看到“完成”按钮,因为用户只需选择另一个选项卡即可停止音频。

显然,将 AV 文件置于后台是有意义的,因为 MPMoviePlayerController 对象旨在播放视频,并且视频应该位于前面。它是一致的,因为音频也进入背景..除了我需要一种方法来击败来到前面的音频/QuickTime((Q))图形。

我确实插入了代码来确定它是音频文件(mp3)还是视频文件(mp4)。到目前为止一切都很好...然后,如果它是一个音频文件,在我的实际播放片段中,我有:

if ( NSClassFromString(@"MPMoviePlayerViewController") )
{
    if (!isAudioFile)
    {
        [senderViewController
         presentMoviePlayerViewControllerAnimated:moviePlayerViewController_];
    }
}

[moviePlayerController_ play];

它实际上有效,也就是说,我实际上在背景中听到了 mp3,歌词在前面,音频/ QuickTime (( Q )) 图形不显示...

但是,发生的事情很可怕,也就是说,“完成”按钮显示在歌词上 我与某种未知的人谈论过? ?那里有字母。

Reference iOS TabController app...

Apple docs state that the AVAudioPlayer class does not provide support for streaming audio based on HTTP URL's. AVAudioPlayer plays only music embedded in the iApp with a file:// as a url.

Given that, I do use MPMoviePlayerViewController to play these web stored audio/mp3 files which it can handle.

This definitely works. I start out with a UIView with the lyrics for the song. At the very bottom of this UIView is a "Play" button. The user taps this button and the audio/mp3 plays; however, the audio/QuickTime (( Q )) graphic comes to the foreground and the lyrics disappear and will stay away until the user taps "Done". What I want to happen is that the audio/mp3 is played in the background, with the lyrics staying in front.

BTW, I really don't need for the "Done" button to be seen because the user can stop the audio by simply selecting another Tab.

Obviously this going to the background for the AV file makes sense because the MPMoviePlayerController object is designed to play video and the video ought to come to the front. It is consistent in that the audio also goes to the background .. except I need a way to defeat the audio/QuickTime (( Q )) graphic coming to the front.

I did insert code to determine if it was an audio file (mp3), versus a video file (mp4). So far so good ... and then if it was an audio file, within my actual playing segment, I have:

if ( NSClassFromString(@"MPMoviePlayerViewController") )
{
    if (!isAudioFile)
    {
        [senderViewController
         presentMoviePlayerViewControllerAnimated:moviePlayerViewController_];
    }
}

[moviePlayerController_ play];

It actually works, that is, I actually hear the mp3 in the background, with the lyrics in front and the audio/QuickTime (( Q )) graphic does not show ...

BUT, what does happen is horrible, that is, the "Done" button shows over the lyrics I talked about with some sort of unknown ??? letters there.

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

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

发布评论

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

评论(1

苦笑流年记忆 2024-12-05 06:55:57

以下答案取自对问题的编辑:

if ( NSClassFromString(@"MPMoviePlayerViewController") )
{
    if (!isAudioFile)
    {
        [senderViewController
         presentMoviePlayerViewControllerAnimated:moviePlayerViewController_];
    }
    else
    {
        [moviePlayerController_ setControlStyle:MPMovieControlStyleNone];
    }
}

FWIW,我真的不需要“完成”按钮,因为一旦我转到另一个选项卡,无论是新音乐还是视频,最初播放的音乐就会停止,新的音乐就会停止。 AV 文件开始。

The following answer is taken from an edit to the question:

if ( NSClassFromString(@"MPMoviePlayerViewController") )
{
    if (!isAudioFile)
    {
        [senderViewController
         presentMoviePlayerViewControllerAnimated:moviePlayerViewController_];
    }
    else
    {
        [moviePlayerController_ setControlStyle:MPMovieControlStyleNone];
    }
}

FWIW, I really don't need a "Done" button because as soon as I go to another tab, either new music or a video, the music initially playing stops and the new AV file starts.

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