RK:视屏播放问题
一. 遇到的问题
1.1.Android OS RK3368 Android6.0 视频播放器不能正常使用
1 2 3 4 5 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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
1 2 3 4 5 6 7 8 9 10 11 12 | <?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
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 | 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(); } } |
加个权限
1 2 3 | <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" /> |
线上视频
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 | <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> |
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 | 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 ; } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】