Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MediaPlayer URL's with Cookie

I have an android application that plays music from a site, however to authenticate to the stream, you need to send a cookie first I.E:

http://example.com/site/content?id=SOMEID = mp3 formatted stream

If you access the url without a cookie, you'll get a Server 500 error. If you have a cookie, then you'll get the stream.

For the life of me, I can't figure out how to make the mediaplayer play a URL while sending a cookie.

I can play any url that doesn't require a cookie, however.

like image 796
WedTM Avatar asked Oct 15 '22 16:10

WedTM


2 Answers

As far as I can tell you can't. Almost everything MediaPlayer does is done in native code, including opening any connections, so there is no way to access the stream it is using AFAICT.

like image 119
sooniln Avatar answered Oct 20 '22 12:10

sooniln


One possible workaround is to create a web server in your Android app, have it authenticate and download your MP3 and having your MediaPlayer call setDataSource with your local server's address (something like http://127.0.0.1:8000/mymp3.mp3). You can have the playback occur while your web server class is still downloading so ideally your users would notice a difference.

like image 26
ajacian81 Avatar answered Oct 20 '22 11:10

ajacian81