Salve a tutti, sto realizzando un'app che integra un mediaplayer, tutto ok su android 3.x e superiori ma sulle versioni 2.x mi da errore.
Ho esteso la classe android costruendomi un paio di metodi personalizzati e cercando di gestirmi gli errori come avevo trovato anche su un altro forum ma nulla non riesco ad uscirne. Questa è la classe android che estende mediaplayer.
codice:
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);
prepareAsync();
} catch (Exception e) {
return false;
}
return true;
}
e questo è il logcat limitato agli errori del mediaplayer, il filtro è su verbose quindi non ho nessun altro messaggio da parte dell'emulatore se non questi errori.
codice:
05-03 10:15:06.699: E/MediaPlayer(414): Attempt to call getDuration without a 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)
in realtà la consequenzialità degli stati stando alle api ufficiali è corretta e su android 4 infatti ripeto che va correttamente. idee o suggerimenti?
EDIT:
il player funziona con i files sulla SD ma non funziona con i files su internet, questo sempre per quanto riguarda 2.x sul 4 tutto ok. anche perchè nel manifest ho scritto tutto correttamente
codice:
<uses-permission android:name="android.permission.INTERNET" />