media player - Error streaming file on android 2.x, working on 4.x -
i wrote class extends android mediaplayer, class following
package it.ccevas.ccevasandroid; import java.io.ioexception; import android.media.audiomanager; import android.media.mediaplayer; public class mymediaplayer extends mediaplayer { public mymediaplayer(){ super(); setonpreparedlistener(new onpreparedlistener() { public void onprepared(mediaplayer mp) { start(); } }); setonerrorlistener(new onerrorlistener() { @override public boolean onerror(mediaplayer mp, int what, int extra) { if (what == -38){ return true; } return false; } }); } public boolean changesource (string urlfile){ try{ reset(); setaudiostreamtype(audiomanager.stream_music); setdatasource(urlfile); prepare(); seekto(0); } catch (illegalargumentexception e1) { e1.printstacktrace(); } catch (securityexception e1) { e1.printstacktrace(); } catch (illegalstateexception e1) { e1.printstacktrace(); } catch (ioexception e1) { e1.printstacktrace(); } start(); return true; } }
it works fine on android 4.x
but on android 2.x works files stored on sd , not working remote files eg. "http://www.something.com/myfile.mp3"
permission on manifest right < uses-permission android:name="android.permission.internet" />
this log.cat
05-03 10:15:06.699: e/mediaplayer(414): attempt call getduration without valid mediaplayer 05-03 10:15:06.699: e/mediaplayer(414): error (-38, 0) 05-03 10:15:06.699: e/mediaplayer(414): error (1, -2147483648) 05-03 10:15:06.789: e/mediaplayer(414): error (-38,0) 05-03 10:15:57.991: e/mediaplayer(414): error (1,-2147483648)
you try new url instead of "http://www.something.com/myfile.mp3" because url not prepare server.
Comments
Post a Comment