RK:视屏播放问题
一. 遇到的问题
1.1.Android OS RK3368 Android6.0 视频播放器不能正常使用
6-15 13:44:27.914 E/RockFFPlayer( 198): open /storage/emulated/0/Android/data/com.howfor.player/file/howfor_player/resource/opt/resources/视频/视频/汇晟招商.mp4 fail 06-15 13:44:27.914 E/RockFFPlayer( 198): ffmpeg version v2.1: git-2018-01-29-c6ebc84 06-15 13:44:27.915 E/RockFFPlayer( 198): init_input:avio_open2 failed 06-15 13:44:27.915 E/RockFFPlayer( 198): init_input failed 06-15 13:44:27.915 I/RockFFPlayer( 198): avformat_open_input return fail
解决:更新vpu相关库,vendor/rockchip/common/vpu/lib/
1.2.Android OS RK3128 Android5.1
2-28 13:53:26.665 I/cr_MediaCodecBridge( 2680): create MediaCodec video decoder, mime video/avc 12-28 13:53:26.675 I/OMXClient( 2680): Using client-side OMX mux. 12-28 13:53:26.709 W/OMXNodeInstance( 160): [36:rk._decoder.avc] component does not support metadata mode; using fallback 12-28 13:53:26.711 E/ACodec ( 2680): [OMX.rk.video_decoder.avc] storeMetaDataInBuffers failed w/ err -1010 12-28 13:53:26.719 E/ROCKCHIP_VIDEO_DECCONTROL( 160): decoder width 3840 big than support width 1920 return error 12-28 13:53:26.719 E/OMXNodeInstance( 160): setParameter(36:rk._decoder.avc, ParamPortDefinition(0x2000001)) ERROR: BadParameter(0x80001005) 12-28 13:53:26.719 E/ACodec ( 2680): [OMX.rk.video_decoder.avc] configureCodec returning error -2147483648 12-28 13:53:26.719 E/ACodec ( 2680): signalError(omxError 0x80001001, internalError -2147483648) 12-28 13:53:26.719 E/MediaCodec( 2680): Codec reported err 0x80001001, actionCode 0, while in state 3 12-28 13:53:26.719 E/MediaCodec( 2680): configure failed with err 0x80001001, resetting... 12-28 13:53:26.731 I/OMXClient( 2680): Using client-side OMX mux. 12-28 13:53:26.739 E/cr_MediaCodecBridge( 2680): Cannot configure the video codec 12-28 13:53:26.739 E/cr_MediaCodecBridge( 2680): android.media.MediaCodec$CodecException: Error 0x80001001 12-28 13:53:26.739 E/cr_MediaCodecBridge( 2680): at android.media.MediaCodec.native_configure(Native Method) 12-28 13:53:26.739 E/cr_MediaCodecBridge( 2680): at android.media.MediaCodec.configure(MediaCodec.java:577) 12-28 13:53:26.739 E/cr_MediaCodecBridge( 2680): at org.chromium.media.MediaCodecBridge.a(PG:7) 12-28 13:53:26.739 E/cr_MediaCodecBridge( 2680): at org.chromium.media.MediaCodecBridgeBuilder.createVideoDecoder(PG:67) 12-28 13:53:26.751 E/chromium( 2680): [ERROR:batching_media_log.cc(38)] MediaEvent: {"error":"video decoder reinitialization failed"} 12-28 13:53:26.779 E/chromium( 2680): [ERROR:batching_media_log.cc(35)] MediaEvent: {"pipeline_error":3} 12-28 13:53:29.722 W/ALooperRoster( 2680): failed to deliver message. Target handler not registered
解决:3128 最大解码分辨率就是 1920*1080
二.APK:播放资源文件中的视频 、播放网络资源
使用VideoView
2. 1.把视频文件放到项目工程的 res/raw 文件下。
2.2.视频文件必须是Android支持视频格式(3gp, wmv, mp4)
三.代码
3.1.activity_video.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <VideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="1200dp" android:layout_gravity="center"/> </LinearLayout>
3.2.VideoPlayer.java
package com.gatsby.test; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.widget.VideoView; import androidx.appcompat.app.AppCompatActivity; public class VideoPlayer extends AppCompatActivity { VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); videoView = (VideoView) findViewById(R.id.videoView); videoView.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/raw/test")); videoView.start(); } }
加个权限
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
线上视频
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context="com.gatsby.splitscreenplayer.MainActivity" > <VideoView android:id="@+id/mVideoView" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="START" /> <Button android:id="@+id/btn_pause" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="PAUSE" /> <Button android:id="@+id/btn_repetition" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> </LinearLayout> </LinearLayout>
package com.gatsby.splitscreenplayer; import android.app.Activity; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import android.widget.VideoView; public class MainActivity extends Activity implements OnClickListener { private Button btn_start, btn_pause, btn_stop; VideoView videoView = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn_start = (Button) findViewById(R.id.btn_start); Button btn_pause = (Button) findViewById(R.id.btn_pause); Button btn_repetition = (Button) findViewById(R.id.btn_repetition); btn_start.setOnClickListener(this); btn_pause.setOnClickListener(this); btn_repetition.setOnClickListener(this); videoView = (VideoView) findViewById(R.id.mVideoView); videoView.setVideoURI(Uri.parse("http://vfx.mtime.cn/Video/2019/03/19/mp4/190319222227698228.mp4")); videoView.start(); videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Toast.makeText(MainActivity.this, "播放完成了", Toast.LENGTH_SHORT).show(); } }); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_start: videoView.start(); break; case R.id.btn_pause: videoView.pause(); break; case R.id.btn_repetition: break; default: break; } } }