Skip to content

Commit

Permalink
1.将StandardVideoController移到demo,方便扩展与定制
Browse files Browse the repository at this point in the history
2.增加清晰度切换功能
3.改进“居中裁剪”算法
  • Loading branch information
Doikki committed Apr 18, 2018
1 parent 0887e5e commit 816ed23
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 85 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ A video player based on [IjkPlayer](https://github.com/Bilibili/ijkplayer).
* **支持封面。**
* **支持锁定/解锁全屏。**
* **支持调整显示比例:默认、原始大小、16:9、4:3、铺满屏幕、居中裁剪。**
* **暂停时前后台切换不黑屏**
* **支持IJKPlayer和MediaPlayer切换。**
* **支持Https协议。**
* **支持rtsp,concat协议。**
* **支持连续播放一个列表的视频。**
* **支持广告播放。**
* **支持清晰度切换。**
* **支持弹幕,使用了[DanmakuFlameMaster](https://github.com/Bilibili/DanmakuFlameMaster)**
* **抖音demo。**

Expand All @@ -41,14 +41,14 @@ allprojects {
dependencies {
# required, enough for most devices.
implementation 'com.github.dueeeke.dkplayer:dkplayer-java:2.2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-armv7a:2.2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-java:2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-armv7a:2.3'
# Other ABIs: optional
implementation 'com.github.dueeeke.dkplayer:dkplayer-armv5:2.2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-arm64:2.2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-x86:2.2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-x86_64:2.2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-armv5:2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-arm64:2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-x86:2.3'
implementation 'com.github.dueeeke.dkplayer:dkplayer-x86_64:2.3'
}
```
或者将library下载并导入项目中使用
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" />
<activity
android:name=".activity.api.MultiRatePlayerActivity"
android:name=".activity.api.DefinitionPlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class ApiActivity extends AppCompatActivity {

private static final String VOD_URL = "http://mov.bn.netease.com/open-movie/nos/flv/2017/01/03/SC8U8K7BC_hd.flv";
// private static final String VOD_URL = "https://aweme.snssdk.com/aweme/v1/play/?video_id=47a9d69fe7d94280a59e639f39e4b8f4&line=0&ratio=720p&media_type=4&vr_type=0";
// private static final String VOD_URL = "https://aweme.snssdk.com/aweme/v1/play/?video_id=3fdb4876a7f34bad8fa957db4b5ed159&line=0&ratio=720p&media_type=4&vr_type=0";
//断线自动重连,需加上ijkhttphook:
// private static final String VOD_URL = "ijkhttphook:http://mov.bn.netease.com/open-movie/nos/flv/2017/01/03/SC8U8K7BC_hd.flv";
private static final String LIVE_URL = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
Expand Down Expand Up @@ -48,6 +48,6 @@ public void skipToCustomPlayer(View view) {
}

public void skipToMultiRatePlayer(View view) {
startActivity(new Intent(this, MultiRatePlayerActivity.class));
startActivity(new Intent(this, DefinitionPlayerActivity.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import android.view.MenuItem;

import com.dueeeke.dkplayer.R;
import com.dueeeke.dkplayer.widget.controller.MultiRateController;
import com.dueeeke.dkplayer.widget.videoview.MultiRateIjkVideoView;
import com.dueeeke.dkplayer.widget.controller.DefinitionController;
import com.dueeeke.dkplayer.widget.videoview.DefinitionIjkVideoView;
import com.dueeeke.videoplayer.player.PlayerConfig;

import java.util.LinkedHashMap;
Expand All @@ -18,9 +18,9 @@
* Created by Devlin_n on 2017/4/7.
*/

public class MultiRatePlayerActivity extends AppCompatActivity {
public class DefinitionPlayerActivity extends AppCompatActivity {

private MultiRateIjkVideoView ijkVideoView;
private DefinitionIjkVideoView ijkVideoView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -33,16 +33,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
ijkVideoView = findViewById(R.id.player);

MultiRateController controller = new MultiRateController(this);
DefinitionController controller = new DefinitionController(this);
ijkVideoView.setPlayerConfig(new PlayerConfig.Builder()
.autoRotate()//自动旋转屏幕
// .usingAndroidMediaPlayer()
.build());

LinkedHashMap<String, String> videos = new LinkedHashMap<>();
videos.put("高清", "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4");
videos.put("超清", "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f30.mp4");
ijkVideoView.setMultiRateVideos(videos);
videos.put("标清", "http://mov.bn.netease.com/open-movie/nos/flv/2017/07/24/SCP786QON_sd.flv");
videos.put("高清", "http://mov.bn.netease.com/open-movie/nos/flv/2017/07/24/SCP786QON_hd.flv");
videos.put("超清", "http://mov.bn.netease.com/open-movie/nos/flv/2017/07/24/SCP786QON_shd.flv");
ijkVideoView.setDefinitionVideos(videos);
ijkVideoView.setVideoController(controller);
ijkVideoView.setTitle("韩雪:积极的悲观主义者");
ijkVideoView.start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dueeeke.dkplayer.interf;

import com.dueeeke.videoplayer.listener.MediaPlayerControl;

import java.util.LinkedHashMap;

/**
* 清晰度
* Created by xinyu on 2017/12/25.
*/

public interface DefinitionMediaPlayerControl extends MediaPlayerControl {
LinkedHashMap<String, String> getDefinitionData();
void switchDefinition(String definition);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ protected int setProgress() {
if (mediaPlayer == null) {
return 0;
}
int position = mediaPlayer.getCurrentPosition();
int duration = mediaPlayer.getDuration();

int position = (int) mediaPlayer.getCurrentPosition();
int duration = (int) mediaPlayer.getDuration();

if (adTime != null)
adTime.setText(String.format("%s | 跳过", (duration - position) / 1000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import android.widget.TextView;

import com.dueeeke.dkplayer.R;
import com.dueeeke.dkplayer.interf.MultiRateMediaPlayerControl;
import com.dueeeke.dkplayer.interf.DefinitionMediaPlayerControl;
import com.dueeeke.videoplayer.player.IjkVideoView;
import com.dueeeke.videoplayer.util.L;
import com.dueeeke.videoplayer.util.WindowUtil;

import java.util.ArrayList;
Expand All @@ -27,11 +29,11 @@
import java.util.Map;

/**
* 多码率控制器
* 清晰度切换控制器
* Created by Devlin_n on 2018/4/16.
*/

public class MultiRateController extends StandardVideoController {
public class DefinitionController extends StandardVideoController {
protected TextView multiRate;
// private PopupMenu mPopupMenu;
private PopupWindow mPopupWindow;
Expand All @@ -40,15 +42,15 @@ public class MultiRateController extends StandardVideoController {
private LinearLayout mPopLayout;


public MultiRateController(@NonNull Context context) {
public DefinitionController(@NonNull Context context) {
this(context, null);
}

public MultiRateController(@NonNull Context context, @Nullable AttributeSet attrs) {
public DefinitionController(@NonNull Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}

public MultiRateController(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
public DefinitionController(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

Expand All @@ -65,6 +67,18 @@ protected void initView() {
mPopupWindow.setClippingEnabled(false);
}

@Override
public void setPlayerState(int playerState) {
super.setPlayerState(playerState);
switch (playerState) {
case IjkVideoView.PLAYER_NORMAL:
multiRate.setVisibility(GONE);
break;
case IjkVideoView.PLAYER_FULL_SCREEN:
multiRate.setVisibility(VISIBLE);
break;
}
}

@Override
public void onClick(View v) {
Expand Down Expand Up @@ -94,9 +108,9 @@ private void showRateMenu() {
@Override
protected int setProgress() {
if (multiRate != null && TextUtils.isEmpty(multiRate.getText())) {

LinkedHashMap<String, String> multiRateData = ((MultiRateMediaPlayerControl) mediaPlayer).getMultiRateData();

L.d("multiRate");
LinkedHashMap<String, String> multiRateData = ((DefinitionMediaPlayerControl) mediaPlayer).getDefinitionData();
if (multiRateData == null) return super.setProgress();
mRateStr = new ArrayList<>();
mRateItems = new ArrayList<>();
int index = 0;
Expand Down Expand Up @@ -128,8 +142,9 @@ public void onClick(View v) {
mRateItems.get(currentIndex).setTextColor(Color.BLACK);
mRateItems.get(index).setTextColor(ContextCompat.getColor(getContext(), R.color.theme_color));
multiRate.setText(mRateStr.get(index));
((MultiRateMediaPlayerControl) mediaPlayer).switchRate(mRateStr.get(index));
((DefinitionMediaPlayerControl) mediaPlayer).switchDefinition(mRateStr.get(index));
mPopupWindow.dismiss();
hide();
currentIndex = index;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ protected int setProgress() {
if (mediaPlayer == null || isDragging) {
return 0;
}
int position = mediaPlayer.getCurrentPosition();
int duration = mediaPlayer.getDuration();
int position = (int) mediaPlayer.getCurrentPosition();
int duration = (int) mediaPlayer.getDuration();
if (videoProgress != null) {
if (duration > 0) {
videoProgress.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ protected int setProgress() {
if (mediaPlayer == null || isDragging) {
return 0;
}
int position = mediaPlayer.getCurrentPosition();
int duration = mediaPlayer.getDuration();
int position = (int) mediaPlayer.getCurrentPosition();
int duration = (int) mediaPlayer.getDuration();
if (videoProgress != null) {
if (duration > 0) {
videoProgress.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public void release() {
}

@Override
public void seekTo(int pos) {
public void seekTo(long pos) {
super.seekTo(pos);
if (isInPlaybackState()) {
if (mDanmakuView != null) mDanmakuView.seekTo((long) pos);
if (mDanmakuView != null) mDanmakuView.seekTo(pos);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import com.dueeeke.dkplayer.interf.MultiRateMediaPlayerControl;
import com.dueeeke.dkplayer.interf.DefinitionMediaPlayerControl;
import com.dueeeke.videoplayer.player.IjkVideoView;
import com.dueeeke.videoplayer.util.L;

import java.util.LinkedHashMap;

/**
* 多码率
* 清晰度切换
* Created by xinyu on 2018/4/16.
*/

public class MultiRateIjkVideoView extends IjkVideoView implements MultiRateMediaPlayerControl{
public class DefinitionIjkVideoView extends IjkVideoView implements DefinitionMediaPlayerControl {
private LinkedHashMap<String, String> mMultiRateVideoModels;
private String mCurrentDefinition;

public MultiRateIjkVideoView(@NonNull Context context) {
public DefinitionIjkVideoView(@NonNull Context context) {
super(context);
}

public MultiRateIjkVideoView(@NonNull Context context, @Nullable AttributeSet attrs) {
public DefinitionIjkVideoView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public MultiRateIjkVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public DefinitionIjkVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
public LinkedHashMap<String, String> getMultiRateData() {
public LinkedHashMap<String, String> getDefinitionData() {
return mMultiRateVideoModels;
}

@Override
public void switchRate(String type) {
L.d(type);
String url = mMultiRateVideoModels.get(type);
if (url.equals(mCurrentUrl)) return;
public void switchDefinition(String definition) {
String url = mMultiRateVideoModels.get(definition);
if (definition.equals(mCurrentDefinition)) return;
mCurrentUrl = url;
addDisplay();
getCurrentPosition();
startPrepare(true);
mCurrentDefinition = definition;
}

public void setMultiRateVideos(LinkedHashMap<String, String> videos) {
public void setDefinitionVideos(LinkedHashMap<String, String> videos) {
this.mMultiRateVideoModels = videos;
this.mCurrentUrl = getValueFromLinkedMap(videos, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_multi_rate_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_height="match_parent"
android:orientation="vertical">

<com.dueeeke.dkplayer.widget.videoview.MultiRateIjkVideoView
<com.dueeeke.dkplayer.widget.videoview.DefinitionIjkVideoView
android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="250dp" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/layout_rate_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
android:textSize="16sp"
android:background="#fff"
android:textColor="#000"
android:gravity="center"
tools:text="高清" />
10 changes: 4 additions & 6 deletions app/src/main/res/layout/layout_standard_controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@
android:id="@+id/curr_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/default_spacing"
android:layout_marginStart="@dimen/default_spacing"
android:textColor="@android:color/white"
android:textSize="@dimen/controller_time_text_size"
tools:text="00:00" />
Expand All @@ -111,8 +109,6 @@
android:id="@+id/total_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/default_spacing"
android:layout_marginRight="@dimen/default_spacing"
android:textColor="@android:color/white"
android:textSize="@dimen/controller_time_text_size"
tools:text="00:00" />
Expand All @@ -121,10 +117,12 @@
android:id="@+id/tv_multi_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/default_spacing"
android:layout_marginRight="@dimen/default_spacing"
android:textColor="@android:color/white"
android:textSize="@dimen/controller_time_text_size"
android:layout_marginLeft="@dimen/default_spacing"
android:layout_marginStart="@dimen/default_spacing"
android:visibility="gone"
tools:visibility="visible"
tools:text="高清" />

<ImageView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ protected void slideToChangePosition(float deltaX) {
mCenterView.setProVisibility(View.GONE);
deltaX = -deltaX;
int width = getMeasuredWidth();
int duration = mediaPlayer.getDuration();
int currentPosition = mediaPlayer.getCurrentPosition();
int duration = (int) mediaPlayer.getDuration();
int currentPosition = (int) mediaPlayer.getCurrentPosition();
int position = (int) (deltaX / width * duration + currentPosition);
if (position > currentPosition) {
mCenterView.setIcon(R.drawable.ic_action_fast_forward);
Expand Down
Loading

0 comments on commit 816ed23

Please sign in to comment.