开发者

playing audio with MPMoviePlayerViewController

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 MPMoviePla开发者_开发知识库yerController 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜