MediaPlayer播放视频单曲循环播放无缝对接,不黑屏,播放到最后使用seekto(0)
+ private void setLooping()
+ {
+ //Log.d(TAG, ">ZC< setLooping()------");
+ post(new Runnable() {
+ @Override
+ public void run() {
+ if (mMediaPlayer != null){
+ if(mMediaPlayer.getDuration()>0 && getCurrentPosition()>0){
+ if (mMediaPlayer.getDuration() - getCurrentPosition()<=1000){
+ Log.d(TAG, ">ZC< player play mode is MODE_ONE_LOOP");
+ mMediaPlayer.seekTo(0);
+ }
+ }
+ }
+ }
+ });
+ }
private void setVideoURI(String url)
{
Log.d(TAG, ">HSQ< setVideoURI() url: "+url);
@@ -1364,17 +1398,55 @@ MMediaPlayer.OnSeekCompleteListener, MMediaPlayer.OnErrorListener, MMediaPlayer.
@Override
public void handleMessage(Message msg)
{
- Log.d(TAG, ">HSQ< handleMessage() msg.what:" + msg.what);
- try
- {
- Log.d(TAG, ">HSQ< setDisplayMode:" + displayMode);
- setLayoutParams(layoutParams);
- } catch (Exception e)
- {
- e.printStackTrace();
- Log.d(TAG, ">HSQ< player [setDisplayMode] error:" + e);
- }
- super.handleMessage(msg);
- }
+ //Log.d(TAG, ">HSQ< handleMessage() msg.what:" + msg.what);
+ super.handleMessage(msg);
+ switch(msg.what)
+ {
+ case 0:
+ {
+ try
+ {
+ Log.d(TAG, ">HSQ< setDisplayMode:" + displayMode);
+ setLayoutParams(layoutParams);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Log.d(TAG, ">HSQ< player [setDisplayMode] error:" + e);
+ }
+ break;
+ }
+ case 1:
+ {
+ try
+ {
+ SharedPreferences pwdPrefs = mContext.getSharedPreferences("system_data", 0);
+ String mode = pwdPrefs.getString("videoPlayMode", "");
+ //Log.d(TAG, ">ZC< player play mode:" + mode);
+ if("MODE_ONE_LOOP".equals(mode)){
+ setLooping();
+ }
+
+ }catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+
+ try
+ {
+ if(mHandler!=null){
+ Message msg1 = new Message();
+ msg1.what = 1;
+ mHandler.sendMessageDelayed(msg1, 450);
+ }
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ break;
+ }
+ }
+
+ }
};
}