Android的媒体播放器的MediaController超时 [英] android mediaplayer mediacontroller timeout

查看:1598
本文介绍了Android的媒体播放器的MediaController超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

香港专业教育学院实施了媒体播放器和MediaController该流的MP3 URL。但是我对网络的Tmobile设备犯规得到一个伟大的3G信号,因此在EDGE运作。林假设媒体播放器崩溃,因为流过慢或不完整的,有没有超时我可以设置?

Ive implemented a mediaplayer and mediacontroller that streams a mp3 url. However my device on the TMobile network doesnt get a great 3G signal so it operates on EDGE. Im assuming that the mediaplayer is crashing because the stream is too slow or incomplete, is there a timeout I can set?

推荐答案

有没有暂停方式中的 MediaPlayer的,但你可以实现它自己 - 有多种方法可以做到这一点。
我建议他们中的一个,我用我自己和它的工作对我来说 - 广播接收器
code看起来就像是:

There is no timeout method in MediaPlayer, but you can implement it yourself - there are variety of ways you can do that. I suggest one of them, that I used myself and it worked for me - BroadcastReceiver Code would look like that:

public class ConnectivityCheckingReceiver extends WakefulBroadcastReceiver
{
  private AlarmManager alarmManager;
  private PendingIntent pendingIntent;

  @Override
  public void onReceive(Context context, Intent intent)
  {
    if (MusicService.mediaPlayer != null)
    {
        if (!MusicService.mediaPlayer.isPlaying())
            Log.v("Music", "Music is NOT playing"); 
            //stop service and notify user
        else
            Log.v("Music", "Music is playing");
    }
    else
    {
        Log.v("Music", "User stopped player");
    }
  }
  public void setAlarm (Context context, int hour, int minute, int second)
  {
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, ConnectivityCheckingReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);      
  }
}

在你的活动/服务/片段您加入这一行:

In your activity/service/fragment you add this line:

ConnectivityCheckingReceiver conCheck = new ConnectivityCheckingReceiver();
conCheck.setAlarm(context, hour, min, second);

您需要实现时/分/秒检查逻辑的事情,但它很容易与图书馆做过类似乔达时间的。
而且不要忘了添加到您的清单:

You will need to implement hour/min/second checking logic yourself, but it's easily done with libraries like Joda Time. And don't forget to add to your manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<receiver android:name=".receivers.ConnectivityCheckingReceiver" />

PS,我的解决方案并不完美,但我还没有看到这个问题的任何好的答案,如果找到了,请分享。

Ps, my solution is not perfect, but I have not seen any good answers for this question, so if find one, please share it.

这篇关于Android的媒体播放器的MediaController超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆