基于jiecaovideo实现类似腾讯新闻视频item不可见小屏播放,item可见时小屏切换到itemy

先上个效果图,基于开源项目jiecaovideo修改,类似于腾讯新闻效果

此特效View为JCVideoPlayerListAutoWindowTiny继承自JCVideoPlayerStandard

Item滑出屏幕后自动小屏播放,Item再次滑入屏幕,则小屏切回Item播放


用法示例

使用JCVideoPlayerListAutoWindowTiny的调用代码

 Object[] youData = {"标题", position + ""};
 jCVideoPlayerListAutoWindowTiny.setUp( "url", JCVideoPlayer.SCREEN_LAYOUT_LIST,youData);

在你使用JCVideoPlayerListAutoWindowTiny的Activity中,其实就是把JCVideoPlayer更换为JCVideoPlayerListAutoWindowTiny
 @Override
    public void onBackPressed() {
        if (JCVideoPlayerListAutoWindowTiny.backPress()) {
            return;
        }
        super.onBackPressed();
    }

源码部分

package fm.jiecao.jcvideoplayer_lib;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by yujunkui
 * On 2016/08/30
 */
public class JCVideoPlayerListAutoWindowTiny extends JCVideoPlayerStandard {


    public String position="-1";//记录播放的position

    public JCVideoPlayerListAutoWindowTiny(Context context) {
        super(context);
    }

    public JCVideoPlayerListAutoWindowTiny(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void init(Context context) {
        super.init(context);
    }

    @Override
    public   boolean setUp(String url, int screen, Object... objects) {
        Log.i(TAG, "setUp [" + this.hashCode() + "]isCurrentMediaListener()=" + isCurrentMediaListener() + " this.currentState == CURRENT_STATE_PLAYING=" + (this.currentState == CURRENT_STATE_PLAYING) + " screen!=SCREEN_WINDOW_FULLSCREEN" + (screen != SCREEN_WINDOW_FULLSCREEN));
        JCVideoPlayerListAutoWindowTiny jcVideoPlayer = null;
        boolean isPlayingTiny=false;//当前是否在播放
        if (JCVideoPlayerManager.listener() != null) {
            jcVideoPlayer = (JCVideoPlayerListAutoWindowTiny) JCVideoPlayerManager.listener();
            isPlayingTiny=jcVideoPlayer.currentScreen==SCREEN_WINDOW_TINY?true:false;
//            Log.i(TAG, "setUp [" + this.hashCode() + "] jcVideoPlayer.objects[1]="+jcVideoPlayer.objects[1]);
        }
        if (isCurrentMediaListener() //当前播放监听是否是自己
                && this.currentState == CURRENT_STATE_PLAYING //正在播放
                && screen != SCREEN_WINDOW_FULLSCREEN //是否在全屏
                && !isFullSwitchList//是否全屏切到listview
                &&!isPlayingTiny) {//在播放
            //启动小屏
            startWindowTiny();
        } else if (jcVideoPlayer != null
                && objects.length>1
//                && jcVideoPlayer.objects[1] != null && objects[1] != null
                && position.equals(objects[1])//position是否一致
                && jcVideoPlayer.currentState == CURRENT_STATE_PLAYING//是否在播放
                && jcVideoPlayer.currentScreen == SCREEN_WINDOW_TINY) {//是否小屏
            Log.i(TAG, "setUp Tiny To List [" + this.hashCode() + "] position="+position+" objects[1]="+objects[1]);
            JCVideoPlayerManager.listener().goToOtherListener();//返回到item播放
        } else {
            isFullSwitchList = false;
        }
        boolean superReturn = super.setUp(url, screen, objects);
        if (currentScreen == SCREEN_WINDOW_TINY) {
            tinyBackImageView.setVisibility(View.INVISIBLE);//设置在小屏下隐藏back
        }
        return superReturn;
    }

    public boolean isFullSwitchList = false;//是否从全屏切换到小屏

    @Override
    public void onClick(View v) {
        super.onClick(v);
        int i = v.getId();
        if (i == R.id.surface_container && currentScreen == SCREEN_WINDOW_TINY) {
            //回调小屏下小屏被点击事件
            Toast.makeText(getContext(),"小屏被点击",Toast.LENGTH_SHORT).show();
        } else if (i == R.id.fullscreen) {
            if (currentScreen != SCREEN_WINDOW_FULLSCREEN) {
                isFullSwitchList = true;//全屏时候做个标识  以便在setup的时候不会切换成小屏
            }
        }else if (i == R.id.thumb||i==R.id.start) {
            position=objects[1].toString();
        }
    }

    public static boolean backPress() {//这个方法如果你没看过源码 基本可能看不懂
        Log.i(TAG, "backPress");
        if (JCVideoPlayerManager.listener() != null) {
            JCVideoPlayerListAutoWindowTiny jcVideoPlayer = (JCVideoPlayerListAutoWindowTiny) JCVideoPlayerManager.listener();
            if (jcVideoPlayer.currentScreen != SCREEN_WINDOW_TINY) {
                if (jcVideoPlayer.currentScreen == SCREEN_WINDOW_FULLSCREEN) {//如果当前是全屏则在切换完后对小屏的isFullSwitchList进行操作
                    boolean b = JCVideoPlayerManager.listener().goToOtherListener();
                    JCVideoPlayerListAutoWindowTiny currentJcVideoPlayer = (JCVideoPlayerListAutoWindowTiny) JCVideoPlayerManager.listener();
                    currentJcVideoPlayer.isFullSwitchList = true;//back标识
                    return b;
                }
                return JCVideoPlayerManager.listener().goToOtherListener();
            }
        }
        return false;
    }

}

放到自己项目直接用即可。注释应该可以看明白

注:这个实现没有详细测试。仅作为参考或者实现思路使用。

阅读更多
版权声明:本文为博主原创文章,可以随意转载 https://blog.csdn.net/u013134391/article/details/52372621
想对作者说点什么? 我来说一句

ListVideoPlayer-master

2015年11月06日 1.98MB 下载

没有更多推荐了,返回首页

不良信息举报

基于jiecaovideo实现类似腾讯新闻视频item不可见小屏播放,item可见时小屏切换到itemy

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭