DetailPlayer.java 18.7 KB
Newer Older
S
shuyu 已提交
1 2
package com.example.gsyvideoplayer;

3 4
import android.app.Activity;
import android.content.Intent;
S
1.3.6  
shuyu 已提交
5
import android.content.res.Configuration;
6 7
import android.database.Cursor;
import android.net.Uri;
S
shuyu 已提交
8
import android.os.Bundle;
S
shuyu 已提交
9

10
import androidx.annotation.Nullable;
S
shuyu 已提交
11 12
import androidx.core.widget.NestedScrollView;
import androidx.appcompat.app.AppCompatActivity;
13 14 15 16

import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
S
shuyu 已提交
17
import android.view.View;
18
import android.widget.Button;
S
shuyu 已提交
19 20 21
import android.widget.ImageView;
import android.widget.RelativeLayout;

S
shuyu 已提交
22
import com.example.gsyvideoplayer.video.LandLayoutVideo;
G
guoshuyu 已提交
23
import com.google.android.exoplayer2.SeekParameters;
G
guoshuyu 已提交
24
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
G
guoshuyu 已提交
25
import com.shuyu.gsyvideoplayer.GSYVideoManager;
G
guoshuyu 已提交
26
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
G
guoshuyu 已提交
27
import com.shuyu.gsyvideoplayer.listener.GSYVideoProgressListener;
G
guoshuyu 已提交
28
import com.shuyu.gsyvideoplayer.model.VideoOptionModel;
S
shuyu 已提交
29
import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer;
S
shuyu 已提交
30

31
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
32
import com.shuyu.gsyvideoplayer.listener.LockClickListener;
33
import com.shuyu.gsyvideoplayer.utils.Debuger;
S
shuyu 已提交
34
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
S
shuyu 已提交
35

S
shuyu 已提交
36

37 38
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
G
guoshuyu 已提交
39
import java.util.ArrayList;
S
shuyu 已提交
40
import java.util.HashMap;
G
guoshuyu 已提交
41
import java.util.List;
S
shuyu 已提交
42
import java.util.Map;
S
shuyu 已提交
43

S
shuyu 已提交
44 45
import butterknife.BindView;
import butterknife.ButterKnife;
G
guoshuyu 已提交
46
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager;
G
guoshuyu 已提交
47
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
S
shuyu 已提交
48 49


S
shuyu 已提交
50
public class DetailPlayer extends AppCompatActivity {
S
shuyu 已提交
51 52 53

    @BindView(R.id.post_detail_nested_scroll)
    NestedScrollView postDetailNestedScroll;
S
shuyu 已提交
54 55 56

    //推荐使用StandardGSYVideoPlayer,功能一致
    //CustomGSYVideoPlayer部分功能处于试验阶段
S
shuyu 已提交
57
    @BindView(R.id.detail_player)
S
shuyu 已提交
58
    LandLayoutVideo detailPlayer;
S
shuyu 已提交
59

S
shuyu 已提交
60 61 62
    @BindView(R.id.activity_detail_player)
    RelativeLayout activityDetailPlayer;

63 64 65 66
    @BindView(R.id.open_btn)
    Button button;


S
1.3.6  
shuyu 已提交
67
    private boolean isPlay;
S
shuyu 已提交
68
    private boolean isPause;
S
shuyu 已提交
69 70 71 72 73 74 75 76 77

    private OrientationUtils orientationUtils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_player);
        ButterKnife.bind(this);

78
        String url = getUrl();
S
shuyu 已提交
79

80
        //detailPlayer.setUp(url, false, null, "测试视频");
81 82
        //detailPlayer.setLooping(true);
        //detailPlayer.setShowPauseCover(false);
S
shuyu 已提交
83 84

        //如果视频帧数太高导致卡画面不同步
S
shuyu 已提交
85
        //VideoOptionModel videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 30);
S
shuyu 已提交
86 87
        //如果视频seek之后从头播放
        //VideoOptionModel videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1);
S
shuyu 已提交
88
        //list<VideoOptionModel> list = new ArrayList<>();
S
shuyu 已提交
89 90
        //list.add(videoOptionModel);
        //GSYVideoManager.instance().setOptionModelList(list);
S
shuyu 已提交
91

92
        //GSYVideoManager.instance().setTimeOut(4000, true);
S
shuyu 已提交
93

G
guoshuyu 已提交
94

G
guoshuyu 已提交
95
        /***************rtsp 配置****************/
G
update  
guoshuyu 已提交
96
        VideoOptionModel videoOptionModel =
G
guoshuyu 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
                new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_clear", 1);
        List<VideoOptionModel> list = new ArrayList<>();
        list.add(videoOptionModel);
        VideoOptionModel videoOptionModel2 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", -1);
        VideoOptionModel videoOptionModel3 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_transport", "tcp");
        VideoOptionModel videoOptionModel4 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_flags", "prefer_tcp");
        VideoOptionModel videoOptionMode04 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0);//是否开启缓冲
        VideoOptionModel videoOptionMode14 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", 1);//是否限制输入缓存数
        VideoOptionModel videoOptionMode15 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "fflags", "nobuffer");
        VideoOptionModel videoOptionMode17 = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzedmaxduration", 100);//分析码流时长:默认1024*1000
        list.add(videoOptionModel2);
        list.add(videoOptionModel3);
        list.add(videoOptionModel4);
        list.add(videoOptionMode04);
        list.add(videoOptionMode14);
        list.add(videoOptionMode15);
        list.add(videoOptionMode17);
G
update  
guoshuyu 已提交
114
        GSYVideoManager.instance().setOptionModelList(list);
G
guoshuyu 已提交
115
        /***************rtsp 配置****************/
G
guoshuyu 已提交
116 117 118 119 120 121 122 123

        /// ijk rtmp
       /*VideoOptionModel videoOptionModel =
                new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "protocol_whitelist", "crypto,file,http,https,tcp,tls,udp,rtmp,rtsp");
        List<VideoOptionModel> list = new ArrayList<>();
        list.add(videoOptionModel);
        GSYVideoManager.instance().setOptionModelList(list);*/

S
shuyu 已提交
124 125 126 127
        //增加封面
        ImageView imageView = new ImageView(this);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(R.mipmap.xxx1);
128 129

        //detailPlayer.setThumbImageView(imageView);
S
shuyu 已提交
130 131 132

        resolveNormalVideoUI();

133
        //外部辅助的旋转,帮助全屏
S
shuyu 已提交
134
        orientationUtils = new OrientationUtils(this, detailPlayer);
S
1.3.6  
shuyu 已提交
135
        //初始化不打开外部的旋转
S
shuyu 已提交
136 137
        orientationUtils.setEnable(false);

G
#2480  
guoshuyu 已提交
138
        /**仅仅横屏旋转,不变直*/
G
guoshuyu 已提交
139
        //orientationUtils.setOnlyRotateLand(true);
G
#2480  
guoshuyu 已提交
140

S
shuyu 已提交
141 142
        Map<String, String> header = new HashMap<>();
        header.put("ee", "33");
143
        header.put("allowCrossProtocolRedirects", "true");
G
guoshuyu 已提交
144
        header.put("User-Agent", "GSY");
145 146
        GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
        gsyVideoOption.setThumbImageView(imageView)
147 148
                .setIsTouchWiget(true)
                .setRotateViewAuto(false)
G
#2480  
guoshuyu 已提交
149
                //仅仅横屏旋转,不变直
G
guoshuyu 已提交
150
                //.setOnlyRotateLand(true)
151
                .setRotateWithSystem(true)
152 153
                .setLockLand(true)
                .setAutoFullWithSize(true)
154 155 156
                .setShowFullAnimation(false)
                .setNeedLockFull(true)
                .setUrl(url)
S
shuyu 已提交
157
                .setMapHeadData(header)
G
guoshuyu 已提交
158
                .setCacheWithPlay(false)
159
                .setVideoTitle("测试视频")
G
guoshuyu 已提交
160
                .setVideoAllCallBack(new GSYSampleCallBack() {
161 162
                    @Override
                    public void onPrepared(String url, Object... objects) {
163 164
                        Debuger.printfError("***** onPrepared **** " + objects[0]);
                        Debuger.printfError("***** onPrepared **** " + objects[1]);
165 166
                        super.onPrepared(url, objects);
                        //开始播放了才能旋转和全屏
167
                        orientationUtils.setEnable(detailPlayer.isRotateWithSystem());
168
                        isPlay = true;
G
guoshuyu 已提交
169

170

G
guoshuyu 已提交
171
                        //设置 seek 的临近帧。
172
                        if (detailPlayer.getGSYVideoManager().getPlayer() instanceof Exo2PlayerManager) {
G
guoshuyu 已提交
173 174 175
                            ((Exo2PlayerManager) detailPlayer.getGSYVideoManager().getPlayer()).setSeekParameter(SeekParameters.NEXT_SYNC);
                            Debuger.printfError("***** setSeekParameter **** ");
                        }
176 177
                    }

178 179 180 181 182 183 184
                    @Override
                    public void onEnterFullscreen(String url, Object... objects) {
                        super.onEnterFullscreen(url, objects);
                        Debuger.printfError("***** onEnterFullscreen **** " + objects[0]);//title
                        Debuger.printfError("***** onEnterFullscreen **** " + objects[1]);//当前全屏player
                    }

185 186 187 188 189 190 191 192 193 194 195 196 197
                    @Override
                    public void onAutoComplete(String url, Object... objects) {
                        super.onAutoComplete(url, objects);
                    }

                    @Override
                    public void onClickStartError(String url, Object... objects) {
                        super.onClickStartError(url, objects);
                    }

                    @Override
                    public void onQuitFullscreen(String url, Object... objects) {
                        super.onQuitFullscreen(url, objects);
198 199
                        Debuger.printfError("***** onQuitFullscreen **** " + objects[0]);//title
                        Debuger.printfError("***** onQuitFullscreen **** " + objects[1]);//当前非全屏player
200 201 202 203 204 205 206 207 208 209 210 211 212
                        if (orientationUtils != null) {
                            orientationUtils.backToProtVideo();
                        }
                    }
                })
                .setLockClickListener(new LockClickListener() {
                    @Override
                    public void onClick(View view, boolean lock) {
                        if (orientationUtils != null) {
                            //配合下方的onConfigurationChanged
                            orientationUtils.setEnable(!lock);
                        }
                    }
G
guoshuyu 已提交
213 214 215 216 217 218 219 220
                })
                .setGSYVideoProgressListener(new GSYVideoProgressListener() {
                    @Override
                    public void onProgress(int progress, int secProgress, int currentPosition, int duration) {
                        Debuger.printfLog(" progress " + progress + " secProgress " + secProgress + " currentPosition " + currentPosition + " duration " + duration);
                    }
                })
                .build(detailPlayer);
221

S
shuyu 已提交
222 223 224
        detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
S
1.3.6  
shuyu 已提交
225 226 227
                //直接横屏
                orientationUtils.resolveByClick();

S
1.3.2  
shuyu 已提交
228 229
                //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
                detailPlayer.startWindowFullscreen(DetailPlayer.this, true, true);
S
shuyu 已提交
230 231
            }
        });
232 233 234 235 236 237 238

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fileSearch();
            }
        });
S
shuyu 已提交
239 240 241 242
    }

    @Override
    public void onBackPressed() {
243 244 245 246 247

        if (orientationUtils != null) {
            orientationUtils.backToProtVideo();
        }

G
guoshuyu 已提交
248
        if (GSYVideoManager.backFromWindowFull(this)) {
S
shuyu 已提交
249 250 251 252 253
            return;
        }
        super.onBackPressed();
    }

S
shuyu 已提交
254 255 256

    @Override
    protected void onPause() {
S
shuyu 已提交
257
        getCurPlay().onVideoPause();
S
shuyu 已提交
258 259 260 261 262 263
        super.onPause();
        isPause = true;
    }

    @Override
    protected void onResume() {
S
shuyu 已提交
264
        getCurPlay().onVideoResume(false);
S
shuyu 已提交
265 266 267 268
        super.onResume();
        isPause = false;
    }

S
shuyu 已提交
269 270 271
    @Override
    protected void onDestroy() {
        super.onDestroy();
S
shuyu 已提交
272 273 274
        if (isPlay) {
            getCurPlay().release();
        }
S
shuyu 已提交
275
        //GSYPreViewManager.instance().releaseMediaPlayer();
S
1.3.3  
shuyu 已提交
276 277
        if (orientationUtils != null)
            orientationUtils.releaseListener();
S
shuyu 已提交
278 279
    }

S
shuyu 已提交
280

281 282 283
    /**
     * orientationUtils 和  detailPlayer.onConfigurationChanged 方法是用于触发屏幕旋转的
     */
S
1.3.6  
shuyu 已提交
284 285 286 287
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //如果旋转了就全屏
S
shuyu 已提交
288
        if (isPlay && !isPause) {
289
            detailPlayer.onConfigurationChanged(this, newConfig, orientationUtils, true, true);
S
1.3.6  
shuyu 已提交
290 291 292
        }
    }

S
shuyu 已提交
293 294 295 296 297 298 299

    private void resolveNormalVideoUI() {
        //增加title
        detailPlayer.getTitleTextView().setVisibility(View.GONE);
        detailPlayer.getBackButton().setVisibility(View.GONE);
    }

S
shuyu 已提交
300 301
    private GSYVideoPlayer getCurPlay() {
        if (detailPlayer.getFullWindowPlayer() != null) {
302
            return detailPlayer.getFullWindowPlayer();
S
shuyu 已提交
303 304 305
        }
        return detailPlayer;
    }
G
readme  
guoshuyu 已提交
306 307 308 309


    private String getUrl() {

G
guoshuyu 已提交
310
        //String url = "android.resource://" + getPackageName() + "/" + R.raw.test;
G
readme  
guoshuyu 已提交
311
        //注意,用ijk模式播放raw视频,这个必须打开
312
        GSYVideoManager.instance().enableRawPlay(getApplicationContext());
G
guoshuyu 已提交
313

G
detail  
guoshuyu 已提交
314 315 316
        ///exo 播放 raw
        //String url = "rawresource://" + getPackageName() + "/" + R.raw.test;

G
guoshuyu 已提交
317
        ///exo raw 支持
G
guoshuyu 已提交
318
        //String url =  RawResourceDataSource.buildRawResourceUri(R.raw.test).toString();
G
readme  
guoshuyu 已提交
319 320 321 322

        //断网自动重新链接,url前接上ijkhttphook:
        //String url = "ijkhttphook:https://res.exexm.com/cw_145225549855002";

G
guoshuyu 已提交
323
        //String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
G
guoshuyu 已提交
324
        //String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
325
        //String url = "http://7xjmzj.com1.z0.glb.clouddn.com/20171026175005_JObCxCE2.mp4";
G
guoshuyu 已提交
326
        //String url = "http://hjq-1257036536.cos.ap-shanghai.myqcloud.com/m3u8/m1/out2.m3u8";
G
guoshuyu 已提交
327
        //String url = "http://223.110.243.138/PLTV/2510088/224/3221227177/index.m3u8";
G
readme  
guoshuyu 已提交
328 329 330 331 332 333 334 335 336
        //String url = "http://qiniu.carmmi.com/image/132451525666042.mp4";
        //String url = "http://ucp.wn.sunmath.cn/file-upload/gYQJHxK9iNQKJeWyS/V80418-103803.mp4?rc_uid=7sCFCGoaF2iTc9vH9&rc_token=prJK-xGutKmy2LDQO-OZASjob0o1u_s3e5SgMHmgjtn";
        //String url = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
        //String url = "file://"+ Environment.getExternalStorageDirectory().getPath() + "Download/132451525666042.mp4";

        //String url =  "http://ipsimg-huabei2.speiyou.cn/010/video/other/20180427/40288b156241ec6301624243bdf7021e/40288b156290270d0162a3e7eb2e0726/1524814477/movie.mp4";
        //String url =  "http://ipsimg-huabei2.speiyou.cn/010/video/other/20180424/40288b156290270d0162a3db8cdd033e/40288b156290270d0162a3e8207f074f/e787a64c-f2d0-48fe-896d-246af05f111a.mp4";

        //String url =  "http://video.7k.cn/app_video/20171202/6c8cf3ea/v.m3u8.mp4";
G
guoshuyu 已提交
337
        //String url =  "http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8";
G
guoshuyu 已提交
338
        //String url = "rtmp://ctc-zhenjiang04.rt1.gensee.com/5324e855b28b453db7b0ec226598b76c_171391_0_8801038305_1591077225_205d01b8/video";
G
guoshuyu 已提交
339
        //String url = "http://video1.dgtle.com/backend%2F2020%2F3%2F0%2F%E6%88%91%E6%B2%A1%E6%9C%89%E7%BB%99%E4%B8%80%E5%8A%A08Pro%E5%81%9A%E8%AF%84%E6%B5%8B_%E5%8D%B4%E5%B8%A6%E7%9D%80%E5%AE%83%E6%BC%82%E6%B5%81.mp4_1080.mp4";
G
guoshuyu 已提交
340
        //String url = "http://yongtaizx.xyz/20191230/t2Axgh3k/index.m3u8";
G
guoshuyu 已提交
341
        //String url = "http://123.56.109.212:8035/users/bfe52074fba74247853caa764b522731/films/orig/aa4c3451-0468-452a-a189-bd064a1963e5-鹿鼎记下.mp4";
342
        //String url = "http://static.hnyequ.cn/yequ_iOS/4940735da1227890e6a261937223e0d2_828x1472.mp4";
G
guoshuyu 已提交
343
        //String url = "http://39.104.119.42/elevator-1.0/api/downFile?path=demo.ogv";
G
update  
guoshuyu 已提交
344
        //String url = "http://pointshow.oss-cn-hangzhou.aliyuncs.com/transcode/ORIGINAL/Mnbc61586842828593.mp4";
G
guoshuyu 已提交
345
        //ssl error
G
update  
guoshuyu 已提交
346
        String url =  "rtsp://admin:zaqwsx123456@192.168.40.181/cam/realmonitor?channel=1&subtype=1";
G
add url  
guoshuyu 已提交
347
        //String url =  "https://us-4.wl-cdn.com/hls/20200225/fde4f8ef394731f38d68fe6d601cfd56/index.m3u8";
G
readme  
guoshuyu 已提交
348 349 350 351
        //String url =  "https://cdn61.ytbbs.tv/cn/tv/55550/55550-1/play.m3u8?md5=v4sI4lWlo4XojzeAjgBGaQ&expires=1521204012&token=55550";
        //String url =  "http://1253492636.vod2.myqcloud.com/2e5fc148vodgzp1253492636/d08af82d4564972819086152830/plHZZoSkje0A.mp4";

        //String url = "rtsp://ajj:12345678@218.21.217.122:65523/h264/ch40/sub/av_stream";
G
guoshuyu 已提交
352 353
        //String url = "rtsp://ajj:ajj12345678@218.21.217.122:65522/h264/ch15/sub/av_stream";
        //String url = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
G
readme  
guoshuyu 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
        //String url = "http://s.swao.cn/o_1c4gm8o1nniu1had13bk1t0l1rq64m.mov";
        //String url = "http://api.ciguang.tv/avideo/play?num=02-041-0491&type=flv&v=1&client=android";
        //String url = "http://video.7k.cn/app_video/20171213/276d8195/v.m3u8.mp4";
        //String url = "http://103.233.191.21/riak/riak-bucket/6469ac502e813a4c1df7c99f364e70c1.mp4";
        //String url = "http://7xjmzj.com1.z0.glb.clouddn.com/20171026175005_JObCxCE2.mp4";
        //String url = "https://media6.smartstudy.com/ae/07/3997/2/dest.m3u8";
        //String url = "http://cdn.tiaobatiaoba.com/Upload/square/2017-11-02/1509585140_1279.mp4";

        //String url = "http://hcjs2ra2rytd8v8np1q.exp.bcevod.com/mda-hegtjx8n5e8jt9zv/mda-hegtjx8n5e8jt9zv.m3u8";
        //String url = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
        //String url = "http://ocgk7i2aj.bkt.clouddn.com/17651ac2-693c-47e9-b2d2-b731571bad37";
        //String url = "http://111.198.24.133:83/yyy_login_server/pic/YB059284/97778276040859/1.mp4";
        //String url = "http://vr.tudou.com/v2proxy/v?sid=95001&id=496378919&st=3&pw=";
        //String url = "http://pl-ali.youku.com/playlist/m3u8?type=mp4&ts=1490185963&keyframe=0&vid=XMjYxOTQ1Mzg2MA==&ep=ciadGkiFU8cF4SvajD8bYyuwJiYHXJZ3rHbN%2FrYDAcZuH%2BrC6DPcqJ21TPs%3D&sid=04901859548541247bba8&token=0524&ctype=12&ev=1&oip=976319194";
        //String url = "http://hls.ciguang.tv/hdtv/video.m3u8";
        //String url = "https://res.exexm.com/cw_145225549855002";
        //String url = "http://storage.gzstv.net/uploads/media/huangmeiyan/jr05-09.mp4";//mepg
G
guoshuyu 已提交
371
        //String url = "https://zh-files.oss-cn-qingdao.aliyuncs.com/20170808223928mJ1P3n57.mp4";//90度
G
readme  
guoshuyu 已提交
372 373
        return url;
    }
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409

    private static final int READ_REQUEST_CODE = 42;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null || resultCode != Activity.RESULT_OK) return;
        if (requestCode == READ_REQUEST_CODE) {
            getPathForSearch(data.getData());
        }
    }


    private void getPathForSearch(Uri uri) {
        String[] selectionArgs = new String[]{DocumentsContract.getDocumentId(uri).split(":")[1]};
        Cursor cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                null, MediaStore.Images.Media._ID + "=?",
                selectionArgs, null);
        if (null != cursor) {
            if (cursor.moveToFirst()) {
                int index = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
                if (index > -1) {
                    detailPlayer.setUp(uri.toString(), false, "File");
                    detailPlayer.startPlayLogic();
                }
            }
            cursor.close();
        }
    }

    protected void fileSearch() {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("video/*");
        startActivityForResult(intent, READ_REQUEST_CODE);
    }
S
shuyu 已提交
410
}