我没有多少经验,所以我从某处复制了代码;但现在我可以得到州媒体播放器;我想做的就是获取媒体播放器的当前状态,然后在播放时显示暂停按钮;暂停/缓冲时播放按钮;
我正在使用shoutcast流媒体;我想在最初加载时显示暂停按钮或加载状态(缓冲);当它被加载并开始播放暂停按钮时;当由于某种原因它再次开始缓冲时,它应该在主要活动上显示播放按钮或加载状态
这是我的代码;
public class Myradio extends AsyncTask implements OnBufferingUpdateListener { private static Context mContext; // private static MyProgressDialog pdialog; public static MediaPlayer mp = new MediaPlayer(); private MediaPlayer mpLoop = new MediaPlayer(); public Myradio(Context theContext) { mContext = theContext; mp.setonBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() { public void onBufferingUpdate(MediaPlayer arg0,int arg1) { Log.v("Buffring Update",""); // Todo Auto-generated method stub } }); } public static void starTradio(String streamUrl) { mp.reset(); mp.setonErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(MediaPlayer mp,int what,int extra) { Log.e(getClass().getName(),"Error in MediaPlayer: (" + what + ") with extra (" + extra + ")"); return false; } }); try { mp.setDataSource(streamUrl); mp.prepare(); mp.start(); } catch (IllegalArgumentException e) { } catch (IllegalStateException e) { } catch (IOException e) { } } public static void stopRadio() { mp.stop(); } public static void resumeRadio() { // mp.(); // mp.setLooping(false); // mpLoop.stop(); } @Override protected Object doInBackground(Object... params) { // Todo Auto-generated method stub return null; } @Override public void onBufferingUpdate(MediaPlayer mp,int percent) { // Todo Auto-generated method stub Log.v("Buffring Update","Buffring Update"); } }