Hi everybody,
I am trying to play a file which is in sdcard using
local server approach,
in the main activity i started SerVer class which extends thread and
open server socket on local emulator waiting for connection,when media
player tries to connect on dummy media file on localhost then server
accepts connection,and i am writing data on to the outputstream of
socket,but the problem is media player is unable to play the song,and
showing Media player errortimeout,though data is successfully written
on socket
the code is as below
public class Media extends Activity {
@Override
void oncreate(){
String localmediafile="http://localhost:4242/x.mp3";
new SerVer(this,this).start();
Thread.sleep(1000);
}
m = new MediaPlayer();
m.setOnPreparedListener(prepare);
m.setAudioStreamType(AudioManager.STREAM_MUSIC);
m.setDataSource(localmediafile);
m.prepare();
}
public class SerVer extends Thread{
@Override
public void run(){
ServerSocket ss = ServerSocketFactory.getDefault().
createServerSocket
(4242,1,InetAddress.getLocalHost());
client = ss.accept();
OutputStream os = client.getOutputStream();
File f = new File("/sdcard/38515.mp3");
InputStream is = new FileInputStream(f);
byte temp[]= new byte[2048];
int numread;
do{
numread = is.read(hare);
if(numread <= 0){
break;
}
else{
Log.i("
writing","bytes"+numread);
os.write(hare, 0, numread);
}
}while(true);
}
Please help if any one have idea
Any help is highly appreciated.
Thanks
Ashok
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en