我试图通过套接字将mp3文件传输到mediaplayer。这是我遵循的文章: http://thinkandroid.wordpress.com/2010/03/27/incorporating-socket-programming-into-your-applications/
我还为媒体播放器添加了代码
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));
}
}
}
我可以看到连接已建立,但我无法从BufferedReader中获取任何内容。这是否意味着MediaPlayer不发送HTTP请求?谢谢!
答案 0 :(得分:0)
对不起,我犯了一个错误。这是我启动这两项服务的方式:
// start server
Thread serverThread = new Thread(new ServerThread());
serverThread.start();
// start mediaplayer
Thread mediaplayerThread = new Thread(new MediaPlayerThread());
mediaplayerThread.start();
完全错误,因为mediaplayerThread可能会在serverThread之前启动。