문제

I want to write an app that plays progressively-downloaded audio from a remote http source through the standard Android mediaplayer, but I want to save a copy of the audio file to the SD card as well. This has proved to be a hard problem:

1) We pass a uri to the media player and are then "cut out of the loop" during playback, because mediaplayer talks directly to the remote thereby not having access to the bytes being played

2) There doesn't seem to be an option for Android to write downloaded bits to disk, nor a callback to access downloaded data

3) While it's possible embed a webserver into our app (see nanohttpd), and then pass a localhost uri into mediaplayer, this seems like a horrible kludge

Am I missing a simpler way? This must be a solved problem?!

Edit: Perhaps a simpler question: if I have a buffer in memory that contains music, can I play it? It seems ridiculous that I have to write it to disk or use a web server to get the mediaplayer to play it.

도움이 되었습니까?

해결책

Yes, there is a way to do this. Create a local proxy server and connect the MediaPlayer to that. See my answer here for a little more detail.

Edit: After looking at this on my PC instead of my phone, I noticed you mention embedding a server in your app. If done properly, it is lightweight and straightforward. And it will give you access to the raw data. I don't think it is a "kludge" at all.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top