... | @@ -646,9 +646,83 @@ mv_video.setMarqueeImage(bitmap, imageWidth, imageHeight); |
... | @@ -646,9 +646,83 @@ mv_video.setMarqueeImage(bitmap, imageWidth, imageHeight); |
|
mv_video.start();
|
|
mv_video.start();
|
|
```
|
|
```
|
|
|
|
|
|
## 4.19 错误处理
|
|
|
|
|
|
## 4.19 小窗播放
|
|
|
|
Android 8.0及以上系统支持小窗播放,具体使用请参考Demo。
|
|
|
|
|
|
|
|
在AndroidManifest.xml文件中给播放Activity配置android:supportsPictureInPicture="true"和android:configChanges="screenLayout|orientation"(避免Activity销毁重建)。
|
|
|
|
|
|
|
|
```
|
|
|
|
<activity
|
|
|
|
android:name=".play.MediaPlayActivity"
|
|
|
|
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
|
|
|
android:screenOrientation="portrait"
|
|
|
|
android:supportsPictureInPicture="true" />
|
|
|
|
```
|
|
|
|
|
|
|
|
进入小窗播放,以下是部分代码示例,详细代码参考Demo:
|
|
|
|
|
|
|
|
```
|
|
|
|
private PictureInPictureParams.Builder builder;
|
|
|
|
|
|
|
|
private void useSmallWindowPlay() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
if (builder == null) {
|
|
|
|
builder = new PictureInPictureParams.Builder();
|
|
|
|
}
|
|
|
|
int width = rl_play_video.getWidth();
|
|
|
|
int height = rl_play_video.getHeight();
|
|
|
|
// 设置宽高比例值
|
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
float whRate = MultiUtils.calFloat(2, width, height);
|
|
|
|
if (whRate > 0.42 && whRate < 2.39) {
|
|
|
|
Rational aspectRatio = new Rational(width, height);
|
|
|
|
builder.setAspectRatio(aspectRatio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actions != null && actions.size() > 0) {
|
|
|
|
actions.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player.isPlaying()) {
|
|
|
|
actions.add(pauseRemoteAction);
|
|
|
|
} else {
|
|
|
|
actions.add(playRemoteAction);
|
|
|
|
}
|
|
|
|
if (actions != null && actions.size() > 0) {
|
|
|
|
builder.setActions(actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 进入小窗模式
|
|
|
|
enterPictureInPictureMode(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 4.20 视频截图
|
|
|
|
通过调用player.getVideoScreenShot(bitmap, videoScreenShotOutPath)获取当前播放视频的截图。
|
|
|
|
|
|
|
|
```
|
|
|
|
private void getVideoScreenShot() {
|
|
|
|
String videoScreenShotOutPath = MultiUtils.getVideoScreenShotOutPath();
|
|
|
|
if (!TextUtils.isEmpty(videoScreenShotOutPath)) {
|
|
|
|
Bitmap bitmap = tv_video.getBitmap();
|
|
|
|
//bitmap:视频画面的bitmap videoScreenShotOutPath:截图输出路径
|
|
|
|
boolean videoScreenShot = player.getVideoScreenShot(bitmap, videoScreenShotOutPath);
|
|
|
|
if (videoScreenShot) {
|
|
|
|
//通知系统相册更新
|
|
|
|
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
|
|
|
|
Uri.fromFile(new File(videoScreenShotOutPath))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 4.21 错误处理
|
|
错误信息有两种,一种是播放器触发的错误,另一种是获得场景视频自定义的错误。
|
|
错误信息有两种,一种是播放器触发的错误,另一种是获得场景视频自定义的错误。
|
|
### 4.19.1 监听播放器的错误事件
|
|
### 4.21.1 监听播放器的错误事件
|
|
DWMediaPlayer重载了MediaPlayer的setOnErrorListener()方法,如果需要在应用中提示错误信息,可调用此方法设置OnErrorListener。具体实现方式如下:
|
|
DWMediaPlayer重载了MediaPlayer的setOnErrorListener()方法,如果需要在应用中提示错误信息,可调用此方法设置OnErrorListener。具体实现方式如下:
|
|
|
|
|
|
```
|
|
```
|
... | @@ -660,7 +734,7 @@ player.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
... | @@ -660,7 +734,7 @@ player.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
}
|
|
}
|
|
});
|
|
});
|
|
```
|
|
```
|
|
### 4.19.2 监听获得场景视频自定义的错误事件
|
|
### 4.21.2 监听获得场景视频自定义的错误事件
|
|
|
|
|
|
```
|
|
```
|
|
player.setOnDreamWinErrorListener(new OnDreamWinErrorListener() {
|
|
player.setOnDreamWinErrorListener(new OnDreamWinErrorListener() {
|
... | @@ -672,9 +746,9 @@ player.setOnDreamWinErrorListener(new OnDreamWinErrorListener() { |
... | @@ -672,9 +746,9 @@ player.setOnDreamWinErrorListener(new OnDreamWinErrorListener() { |
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.20 错误码
|
|
## 4.22 错误码
|
|
|
|
|
|
### 4.20.1 HuodeException自定义的错误码
|
|
### 4.22.1 HuodeException自定义的错误码
|
|
|
|
|
|
```
|
|
```
|
|
101:无播放节点
|
|
101:无播放节点
|
... | @@ -747,7 +821,7 @@ player.setOnDreamWinErrorListener(new OnDreamWinErrorListener() { |
... | @@ -747,7 +821,7 @@ player.setOnDreamWinErrorListener(new OnDreamWinErrorListener() { |
|
505:加载数据失败
|
|
505:加载数据失败
|
|
```
|
|
```
|
|
|
|
|
|
### 4.20.2 ijkplayer错误码
|
|
### 4.22.2 ijkplayer错误码
|
|
|
|
|
|
```
|
|
```
|
|
int MEDIA_INFO_UNKNOWN = 1;//未知信息
|
|
int MEDIA_INFO_UNKNOWN = 1;//未知信息
|
... | | ... | |