Search code examples
androidhttpsocketsmedia-player

MediaPlayer doesn't send HTTP request?


I was trying to transfer a mp3 file to mediaplayer through socket. Here is the article I followed: http://thinkandroid.wordpress.com/2010/03/27/incorporating-socket-programming-into-your-applications/

I also add code for mediaplayer

SERVERADDRESS = "http://" + SERVERIP + ":"+Integer.toString(SERVERPORT);

public class MediaPlayerThread implements Runnable {

    public void run() {
        mediaPlayer = new MediaPlayer();
        try {
        mediaPlayer.setDataSource(SERVERADDRESS);
        mediaPlayer.prepare();
        mediaPlayer.start();
        } catch (Exception e) {
        Log.e("socketExample","Error! " + Log.getStackTraceString(e));
        }
    }
}

I can see the connection is established, but I cannot get anything out of BufferedReader. Does this mean MediaPlayer doesn't send HTTP request? Thanks!


Solution

  • I am sorry I made a mistake. This is the way I launched the two services:

    // start server
    Thread serverThread = new Thread(new ServerThread());
    serverThread.start();
    
    // start mediaplayer
    Thread mediaplayerThread = new Thread(new MediaPlayerThread());
    mediaplayerThread.start();
    

    It is totally wrong because mediaplayerThread may start before serverThread.