使用 MPMoviePlayerViewController 播放音频
参考 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下答案取自对问题的编辑:
FWIW,我真的不需要“完成”按钮,因为一旦我转到另一个选项卡,无论是新音乐还是视频,最初播放的音乐就会停止,新的音乐就会停止。 AV 文件开始。
The following answer is taken from an edit to the question:
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.