MediaPlayer播放视频单曲循环播放无缝对接,不黑屏

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;

+ }

+ }

+

+ }

};

}

6f63a20ec4db4b9490635a3ff4fc5ae3.png

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值