Iphone sdk support for playing mp3 files over the network

人盡茶涼 提交于 2019-11-27 19:21:36

问题


I am writing an application to contact a webserver running on a desktop to access and play mp3 files. Here is what I tried so far: I have used MPMusicPlayerController (and tried UIWebview) to handle the audio file and it automatically plays after progressively downloading the file. There is no way to handle skipping songs and playing after progressive download of a file is not a good solution for cellular network.

Ideally, I would like to have the following function 1. Client requests a stream to be created using a specific bitrate (to handle different network condition) 2. Client should be able to skip songs

Can anyone point me in the right direction? Can m3u8 files support these functions?

Thanks for any help in advance.


回答1:


I ended up using 1. MPMediaPlayback protocol for controlling the MPMoviePlayerController 2. MPMoviePlayerPlaybackDidFinishNotification to determine if the playback completed due to error or due to user input.

The player plays fine both with streaming and Progressive download. The sample MoviePlayer code at http://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007798 is an excellent starting point.




回答2:


Take a look at AVPlayer, it can stream MP3's over the network connection.

        AVPlayer *player = [[AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.mp3.com/mp3file.mp3"]] retain];

    [player play];

Check the documentation.



来源:https://stackoverflow.com/questions/3275990/iphone-sdk-support-for-playing-mp3-files-over-the-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!