admin
2020-09-30 21a3b19894807c46f96e2106a5acb92d8afbd720
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
package com.weikou.beibeivideo.ui.video;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.Toast;
 
import com.fun.xm.Definition;
import com.fun.xm.FSCallback;
import com.fun.xm.FSIVideoPlayer;
import com.fun.xm.FSPlayer;
import com.fun.xm.FSVideoReqData;
import com.fun.xm.ad.FSAD;
import com.fun.xm.ad.FSThirdAd;
import com.fun.xm.ad.adloader.FSPreMediaAdLoader;
import com.fun.xm.ad.adview.FSPreMediaView;
import com.fun.xm.ad.callback.FSPreMediaAdCallBack;
import com.funshion.video.logger.FSLogcat;
import com.funshion.video.util.FSError;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.lcjian.library.RetainViewFragment;
import com.lcjian.library.video.VideoDefinition;
import com.lcjian.library.video.VideoEpisode;
import com.lcjian.library.video.VideoPlayerController;
import com.lcjian.library.widget.RatioLayout;
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.BeibeiVideoApplication;
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.entity.Play;
import com.weikou.beibeivideo.entity.PlayUrl;
import com.weikou.beibeivideo.entity.VideoDetailInfo;
import com.weikou.beibeivideo.entity.VideoInfo;
import com.weikou.beibeivideo.entity.VideoResource;
import com.weikou.beibeivideo.entity.video.FunshionPlayInfo;
import com.weikou.beibeivideo.util.DimenUtils;
import com.weikou.beibeivideo.util.FunshionConstant;
import com.weikou.beibeivideo.util.UserUtil;
import com.weikou.beibeivideo.util.downutil.StringUtils;
import com.weikou.beibeivideo.util.ui.IPageEventListener;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
import de.greenrobot.event.EventBus;
 
public class FunshionPlayerFragment extends RetainViewFragment implements OnClickListener, VideoPlayerController.IVideoPlayerListener {
    private final static String TAG = FunshionPlayerFragment.class.getName();
 
    //媒体视频播放器
    private MediaPlayer mVideoPlayer = new MediaPlayer();
    //视频用 surfaceView
    private SurfaceView mVideoSurfView;
 
    //播放逻辑调度
    private FSIVideoPlayer mFunshionIVideoPlayer;
 
    //清晰度列表
    FSVideoReqData mFSVideoReqData;
    private List<Definition> mDefinitions;
    private Definition mCurrDefinition;
 
    private IPageEventListener pageEventListener;
 
    private VideoInfo mVideoInfo;
    private int mCurrentPosition;
    private PlayUrl playUrl;
    private boolean collected;
    private VideoResource videoResource;
 
    private VideoPlayerController vpc_funshion;
 
    private RatioLayout rl_container;
 
    private FrameLayout fl_container, fl_ad;
 
    //风行广告加载器
    private FSPreMediaAdLoader fsPreMediaAdLoader;
 
    private FSPreMediaView mFSVideoAD;
 
    private FunshionPlayInfo playInfo;
 
    private MediaPlayer mediaPlayer;
 
    public void setPageEventListener(IPageEventListener pageEventListener) {
        this.pageEventListener = pageEventListener;
    }
 
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_player_funshion;
    }
 
    private void initPlayer() {
        mVideoSurfView.getHolder().addCallback(mVideoSurfaceViewCallBack);
        mVideoPlayer.setOnPreparedListener(mOnPreparedListener);
        mVideoPlayer.setOnErrorListener(mOnErrorListener);
        initAccessToken();
        if (getArguments() != null) {
            mVideoInfo = (VideoInfo) getArguments().getSerializable("videoInfo");
            mCurrentPosition = getArguments().getInt("position", 0);
            playUrl = (PlayUrl) getArguments().getSerializable("playUrl");
            collected = getArguments().getBoolean("collect", false);
            videoResource = (VideoResource) getArguments().getSerializable("resource");
 
            playInfo = new FunshionPlayInfo();
            playInfo.setCollected(collected);
            playInfo.setPlayUrl(playUrl);
            playInfo.setPosition(mCurrentPosition);
            playInfo.setVideoInfo(mVideoInfo);
        }
 
    }
 
    private void initAd() {
        FSAD.init(getContext().getApplicationContext(), Collections.singletonList(FunshionConstant.AD_ADP), FunshionConstant.AD_PARTENER, FunshionConstant.AD_TOKEN, FunshionConstant.AD_CHANNEL, FunshionConstant.AD_PRE_DOWNLOAD_CHANNEL);
        fsPreMediaAdLoader = new FSPreMediaAdLoader(getContext(), FunshionConstant.AD_CHANNEL);
    }
 
    private void loadAD() {
        String adid = "bfys_a_qt";
        int width = fl_ad.getWidth();
        int height = fl_ad.getHeight();
        Log.i(TAG, String.format("fl_ad: width:%s  height:%s", width, height));
        fsPreMediaAdLoader.loadAD(adid, "", width, height, true, false, new FSPreMediaAdCallBack() {
            @Override
            public void onCreate(FSPreMediaView fsadView) {
                mFSVideoAD = fsadView;
                fl_ad.removeAllViews();
                fl_ad.addView(fsadView);
            }
 
            @Override
            public void onCreateThirdAD(List<FSThirdAd> fsThirdAd) {
 
            }
 
            @Override
            public void onClose() {
                adShowFinish();
            }
 
            @Override
            public void onADLoad() {
                if (null != mFSVideoAD) {
                    mFSVideoAD.showAD();
                }
            }
 
            @Override
            public void onVideoComplete() {
                adShowFinish();
            }
 
            @Override
            public void onADShow() {
 
            }
 
            @Override
            public void onClick() {
 
            }
 
            @Override
            public void onAdLoadedFail(int param1Int, String param1String) {
                Log.v(TAG, "onAdLoadedFail param1Int:" + param1Int + " MSG:" + param1String);
                adShowFinish();
            }
        });
    }
 
    //广告展示完成
    private void adShowFinish() {
        fl_ad.setVisibility(View.GONE);
        fl_ad.removeAllViews();
        mFSVideoAD = null;
        //播放视频
        mVideoSurfView.postDelayed(new Runnable() {
            @Override
            public void run() {
                EventBus.getDefault().post(playInfo);
            }
        }, 1000);
    }
 
    private void initView(View view) {
        mVideoSurfView = view.findViewById(R.id.video_view);
        vpc_funshion = view.findViewById(R.id.vpc_funshion);
        rl_container = view.findViewById(R.id.rl_container);
        fl_container = view.findViewById(R.id.fl_container);
        fl_ad = view.findViewById(R.id.fl_ad);
    }
 
    //创建广播接受者对象
    BatteryReceiver batteryReceiver = new BatteryReceiver();
    NetworkReceiver networkReceiver = new NetworkReceiver();
 
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //注册receiver
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        initView(contentView);
        initPlayer();
        getContext().registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        getContext().registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
        initAd();
        fl_ad.setVisibility(View.VISIBLE);
        fl_ad.post(new Runnable() {
            @Override
            public void run() {
                loadAD();
            }
        });
 
    }
 
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        getContext().unregisterReceiver(batteryReceiver);
        getContext().unregisterReceiver(networkReceiver);
    }
 
    @Override
    public void onClick(View v) {
 
    }
 
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }
 
    /**
     * 播放视频
     */
    public synchronized void playVideo(String videoID) {
        createPlayer();
        if (mVideoPlayer.isPlaying()) {
            FSLogcat.e(TAG, "Call player to stop");
            mVideoPlayer.stop();
            mVideoPlayer.reset();
        }
        //!!!注意播放长短视频构建的FSVideoReqData有区别。短视频没有epso分集ID。长视频有。填写错误将无法正常播放
        //FSVideoReqData构建需要的数据需要从服务器获取。主要是媒体资源videoID:“VIDEO_ID” 默认 清晰度:new Definition(Definition.CLARITY_LOW) 以及Accesstoken:Accesstoken
        mFSVideoReqData = new FSVideoReqData(videoID, new Definition(Definition.CLARITY_LOW), FunshionConstant.ACCESS_TOKEN);
        try {
            Log.d(TAG, "request");
            mFunshionIVideoPlayer.requestAndPrepare(mFSVideoReqData, FunshionConstant.APICODE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
    /**
     * 播放媒体
     */
    public synchronized void playMedia(String mediaID, String epso) {
        createPlayer();
        if (mVideoPlayer.isPlaying()) {
            FSLogcat.e(TAG, "Call player to stop");
            mVideoPlayer.stop();
            mVideoPlayer.reset();
        }
        //!!!注意播放长短视频构建的FSVideoReqData有区别。短视频没有epso分集ID。长视频有。填写错误将无法正常播放
        //FSVideoReqData构建需要的数据需要从服务器获取。主要是媒体资源videoID:“VIDEO_ID”epso 媒体分集ID 默认 清晰度:new Definition(Definition.CLARITY_LOW) 以及Accesstoken:Accesstoken
        mFSVideoReqData = new FSVideoReqData(mediaID, epso, new Definition(Definition.CLARITY_LOW), FunshionConstant.ACCESS_TOKEN);
        try {
            Log.d(TAG, "request");
            mFunshionIVideoPlayer.requestAndPrepare(mFSVideoReqData, FunshionConstant.APICODE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public synchronized void stopPlay() {
        if (mVideoPlayer != null && mVideoPlayer.isPlaying()) {
            FSLogcat.e(TAG, "Call player to stop");
            mVideoPlayer.stop();
            mVideoPlayer.reset();
        }
    }
 
 
    private void createPlayer() {
        if (mFunshionIVideoPlayer != null) {
            return;
        }
        try {
            //APICODE 为风行派申请的APICODE值
            mFunshionIVideoPlayer = FSPlayer.create(getContext(), mFSCall);
            //可以打开调试信息方便查询问题
            mFunshionIVideoPlayer.setDebug(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private String getDefinitionName(String clarity) {
        switch (clarity) {
            case "tv":
            case "dvd":
                return "标清";
            case "hd":
                return "高清";
            case "sdvd":
                return "超清";
            default:
                return "标清";
        }
 
 
    }
 
    private String videoPlayUrl = "";
 
 
    FSCallback mFSCall = new FSCallback() {
 
        @Override
        public void onDefinition(List<Definition> definitions, Definition currDefinition) {
            for (Definition definition : definitions) {
                Log.e("FE", "get Definition " + definition);
            }
            FunshionPlayerFragment.this.mDefinitions = definitions;
            FunshionPlayerFragment.this.mCurrDefinition = currDefinition;
 
            //设置清晰度
            List<VideoDefinition> vdfList = new ArrayList<>();
            if (definitions != null)
                for (Definition df : definitions) {
                    VideoDefinition vdf = new VideoDefinition();
                    vdf.setClarity(df.getStringDefinition());
                    vdf.setName(getDefinitionName(df.getStringDefinition()));
                    vdfList.add(vdf);
                }
            VideoDefinition vdf = new VideoDefinition();
            vdf.setClarity(mCurrDefinition.getStringDefinition());
            vdf.setName(getDefinitionName(mCurrDefinition.getStringDefinition()));
 
            vpc_funshion.setDefinition(vdfList, vdf);
 
            Toast.makeText(BeibeiVideoApplication.application, "当前清晰度:" + currDefinition.getStringDefinition(), Toast.LENGTH_LONG).show();
        }
 
        @Override
        public void onFailed(FSError arg0) {
            Log.d(TAG, "onFailed" + arg0);
        }
 
        public void onReceiveUrl(String url) {
            Log.d(TAG, "onReceiveUrl" + url);
            try {
                videoPlayUrl = url;
                mVideoPlayer.reset();
                mVideoPlayer.setDataSource(url);
                mVideoPlayer.prepareAsync();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
 
    boolean isReady = false;
 
    int position = 0;
 
    SurfaceHolder.Callback mVideoSurfaceViewCallBack = new SurfaceHolder.Callback() {
 
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            isReady = false;
 
            Log.d(TAG, "surfaceDestroyed");
            if (mVideoPlayer.isPlaying()) {
                position = mVideoPlayer.getCurrentPosition();
                Log.d(TAG, "当前播放时间:" + position);
                mVideoPlayer.stop();
            }
        }
 
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            Log.d(TAG, "surfaceCreated");
            isReady = true;
            mVideoPlayer.setDisplay(holder);
            if (!"".equals(videoPlayUrl) && !mVideoPlayer.isPlaying()) {
                try {
                    mVideoPlayer.reset();
                    mVideoPlayer.setDataSource(videoPlayUrl);
                    mVideoPlayer.prepare();
                    if (position > 0)
                        mVideoPlayer.seekTo(position);
                    position = -1;
                    Log.d(TAG, "续播时间:" + position);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
 
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
 
            Log.d(TAG, "surfaceChanged");
        }
    };
 
 
    MediaPlayer.OnPreparedListener mOnPreparedListener = new MediaPlayer.OnPreparedListener() {
 
        @Override
        public void onPrepared(MediaPlayer mp) {
            Log.i(TAG, "onPrepared");
            mediaPlayer = mp;
            mFunshionIVideoPlayer.onMediaPlayerPrepared();
            autoReSize(mp);
            vpc_funshion.onPrepared(mp);
            if (position > 0)
                mVideoPlayer.seekTo(position);
        }
    };
 
    private void autoReSize(MediaPlayer mp) {
        Log.i(TAG, "autoReSize");
        final int vWidth = mp.getVideoWidth();
        final int vHeight = mp.getVideoHeight();
        if (vHeight == 0 || vWidth == 0)
            return;
        //获取容器的宽
        fl_container.post(new Runnable() {
            @Override
            public void run() {
                float ratio = new BigDecimal(vHeight).divide(new BigDecimal(vWidth), 4, RoundingMode.FLOOR).floatValue();
                int cwidth = fl_container.getWidth();
                int cheight = fl_container.getHeight();
                Log.i(TAG, String.format("MediaPlayer: width-%s  height-%s", vWidth, vHeight));
 
                ViewGroup.LayoutParams params = rl_container.getLayoutParams();
                if (vHeight * cwidth > vWidth * cheight) {
                    Log.i(TAG, "宽自适应");
                    params.height = fl_container.getHeight();
                    params.width = (int) (params.height / ratio);
                } else {
                    Log.i(TAG, "高自适应");
                    params.width = fl_container.getWidth();
                    params.height = (int) (params.width * ratio);
                }
                rl_container.setLayoutParams(params);
 
                rl_container.setRatio(ratio);
                Log.i(TAG, String.format("Ratio: %s", ratio));
 
                mVideoSurfView.post(new Runnable() {
                    @Override
                    public void run() {
                        Log.i(TAG, String.format("mVideoSurfView: width-%s  height-%s", mVideoSurfView.getWidth(), mVideoSurfView.getHeight()));
 
 
                    }
                });
            }
        });
    }
 
    MediaPlayer.OnErrorListener mOnErrorListener = new MediaPlayer.OnErrorListener() {
 
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            mFunshionIVideoPlayer.onMediaPlayerError(what, extra);
            return false;
        }
    };
 
    //TODO 获取AcessToken
    private void initAccessToken() {
 
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
        stopPlay();
        if (mFunshionIVideoPlayer != null) {
            mFunshionIVideoPlayer.onActivityDestroy();
            mFunshionIVideoPlayer.release();
        }
 
 
    }
 
    @Override
    public void onDetach() {
        super.onDetach();
    }
 
    @Override
    public void onStop() {
        super.onStop();
        if (mVideoPlayer != null && mVideoPlayer.isPlaying())
            mVideoPlayer.pause();
 
    }
 
    @Override
    public void onResume() {
        super.onResume();
        if (mFunshionIVideoPlayer != null)
            mFunshionIVideoPlayer.onActivityResume();
        EventBus.getDefault().register(this);
    }
 
    @Override
    public void onPause() {
        super.onPause();
        if (mVideoPlayer.isPlaying())
            mVideoPlayer.pause();
        if (mFunshionIVideoPlayer != null)
            mFunshionIVideoPlayer.onActivityPause();
        EventBus.getDefault().unregister(this);
    }
 
 
    public void requestLayout() {
        Log.i(TAG, "requestLayout");
        if (mediaPlayer != null)
            autoReSize(mediaPlayer);
        else
            autoReSize(mVideoPlayer);
        vpc_funshion.changeOrien(getActivity().getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
 
    //电池电量监控
    class BatteryReceiver extends BroadcastReceiver {
 
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            //判断它是否是为电量变化的Broadcast Action
            if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {//电量变化
                //获取当前电量
                int level = intent.getIntExtra("level", 0);
                //电量的总刻度
                int scale = intent.getIntExtra("scale", 100);
                //把它转成百分比
                if (vpc_funshion != null)
                    vpc_funshion.setBattery((level * 100) / scale);
            }
        }
    }
 
    public class NetworkReceiver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
                vpc_funshion.setNetworkInfo(networkInfo, false);
            }
        }
    }
 
 
    public void onEventMainThread(FunshionPlayInfo info) {
        List<VideoEpisode> episodes = new ArrayList<>();
        for (int i = 0; i < info.getVideoInfo().getVideoDetailList().size(); i++) {
            VideoDetailInfo detail = info.getVideoInfo().getVideoDetailList().get(i);
            VideoEpisode es = new VideoEpisode();
            es.setId(detail.getId());
            es.setTag(detail.getTag());
            es.setVideoId(info.getVideoInfo().getId());
            episodes.add(es);
        }
        mCurrentPosition = info.getPosition();
        vpc_funshion.setContentView(fl_container).setVideoInfo(episodes, info.getVideoInfo().getName(), info.getPlayUrl().getUrl(), info.getPosition()).setVideoPlayerListener(this).build(getActivity(), FunshionPlayerFragment.this);
        //播放视频
//        playVideo(info.getVideoInfo().getVideoDetailList().get(info.getPosition()).getId());
 
        playMedia("99989", (info.getPosition() + 1) + "");
    }
 
    //监听
    @Override
    public void onNext() {
        if (mCurrentPosition >= mVideoInfo.getVideoDetailList().size() - 1) {
            Toast.makeText(getContext(), "没有下一集了", Toast.LENGTH_SHORT).show();
            return;
        }
 
        selectEpisode(mCurrentPosition + 1, null);
    }
 
    @Override
    public void onBack() {//返回
        if (getActivity().getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {//结束
            getActivity().finish();
        }
    }
 
    @Override
    public void onVideoPause() {
 
    }
 
    @Override
    public void onVideoPlay() {
 
    }
 
    @Override
    public void changeDefinition(int p, VideoDefinition definition) {
        Toast.makeText(BeibeiVideoApplication.application, "正在切换清晰度", Toast.LENGTH_SHORT).show();
        if (mVideoPlayer != null && mVideoPlayer.isPlaying())
            position = mVideoPlayer.getCurrentPosition();
        mFunshionIVideoPlayer.changeDefinition(mFSVideoReqData.getUniqueID(), mDefinitions.get(p));
    }
 
    @Override
    public void selectEpisode(int p, VideoEpisode episode) {
        //选集
        final FunshionPlayInfo playInfo = new FunshionPlayInfo();
        playInfo.setVideoInfo(mVideoInfo);
        playInfo.setPosition(p);
        playInfo.setCollected(collected);
        VideoDetailInfo detailInfo = mVideoInfo.getVideoDetailList().get(p);
        String uid = UserUtil.getUid(BeibeiVideoApplication.application);
        BeibeiVideoAPI.getPlayUrl(BeibeiVideoApplication.application, uid, detailInfo.getType(), mVideoInfo.getId(),
                detailInfo.getId(), videoResource.getId(), detailInfo.geteId(),
                new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            Gson gson = new GsonBuilder().setFieldNamingPolicy(
                                    FieldNamingPolicy.UPPER_CAMEL_CASE)
                                    .create();
                            VideoResource resource = gson.fromJson(
                                    jsonObject.getJSONObject("Data")
                                            .getJSONObject("Resource")
                                            .toString(),
                                    new TypeToken<VideoResource>() {
                                    }.getType());
                            PlayUrl info = new PlayUrl();
                            info.setResource(resource);
                            info.setPlayType(Integer.parseInt(jsonObject
                                    .getJSONObject("Data")
                                    .optString("PlayType")));
                            info.setUrl(jsonObject.getJSONObject("Data")
                                    .optString("Url"));
                            info.setParams(jsonObject.getJSONObject("Data")
                                    .optString("Params"));
                            playInfo.setPlayUrl(info);
                            EventBus.getDefault().post(playInfo);
                        }
                    }
                });
    }
 
    @Override
    public void collect(boolean collect) {
 
    }
 
 
}