android stream audio by passing cookies as header
<p>I have to play mp3 audio file from the Server Url. To make the audio to played I need to pass Cookie in the headers. So I used setDatasource(context, uri, headers) to play the media. It's not working for me. </p>

<p>It gives me the error:source returned error -1008, 10 retries left to source returned error -1008, 0 retries left.</p>

<p>Anyone can help me to get a solution for this. Thanks in advance.</p>

<pre><code>MediaPlayer mediaPlayer;

Map headers = new HashMap();
headers.put("Cookie","CloudFront-Signature=xx; Domain=xx; Path=xx");
headers.put("Cookie","CloudFront-Policy:xx; Domain=xx; Path=xx");
headers.put("Cookie","CloudFront-Key-Pair-Id=xx; Domain=xx; Path=XX");

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(MediaPlayerService.this, Uri.parse("URL"),headers);
    mediaPlayer.prepare();
    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    mediaPlayer.start();
                }
            });

**Following are the links referred:**
1. http://stackoverflow.com/questions/731603/android-mediaplayer-urls-with-cookie 
2. http://stackoverflow.com/questions/9727098/android-add-cookie-to-mediaplayer-requests
3. http://stackoverflow.com/questions/2932362/how-to-stream-authenticated-content-with-mediaplayer-on-android 
</code></pre>