我正在使用 Exoplayer 在 android 中连续播放视频作为播放列表。当我播放低质量的 mp4 视频时,它可以正常工作,但是当我在播放列表中播放一两个视频后尝试播放更高质量的 mp4 视频时,屏幕不显示任何内容,并且日志给出以下异常
com.google.android.exoplayer.MediaCodecTrackRenderer$DecoderInitializationException: 解码器初始化失败: OMX.amlogic.avc.decoder.awesome, MediaFormat(video/avc, 198826, 1920, 1080, -1.0, -1, -1, -1, -1, -1)
即使我第一次播放相同的高质量视频,然后第二次抛出此异常。当视频大小超过 80mb 时,会抛出此异常。是缓冲区大小问题吗?有人可以指导我吗?非常感谢您
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adplayertexture);
AdplayerTexture=(TextureView)findViewById(R.id.AdPlayerTexture);
AdplayerTexture.setBackgroundColor(Color.BLACK);
AdplayerTexture.setSurfaceTextureListener(this);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
int height) {
AdPlayerSurface = new Surface( surface);
playMedia(AdPlayerSurface);
}
private void playMedia(Surface surface){
mediaplayer=new ExoPlayer();
mediaplayer.play(this,Videopathlist[CurrentVideoIndex],surface;
mediaplayer.addListener(this);
}
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == ExoPlayer.STATE_ENDED) {
//releasing the resources
mediaplayer.DestroyPlayer();
AdPlayerSurface.release();
AdPlayerSurface=new Surface(AdplayerTexture.getSurfaceTexture());
CurrentVideoIndex++;
playMedia(AdPlayerSurface);
}
这是 root2mediaplayer 类中的函数 play()
public void playMedia(Activity playerActivity,String mediapath,final long Position,Surface mediasurface){
String Systemroot = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
try{
File myFile=new File(Systemroot + java.io.File.separator + "Videos"
+ java.io.File.separator
+ mediapath);
Uri uri = Uri.fromFile(myFile);
final int numRenderers = 2;
SampleSource sampleSource =
new FrameworkSampleSource(playerActivity, uri, /* headers */ null, numRenderers);
// Build the track renderers
TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
// Build the ExoPlayer and start playback
MoviePlayer = ExoPlayer.Factory.newInstance(numRenderers);
MoviePlayer.prepare(videoRenderer, audioRenderer);
MoviePlayer.addListener(this);
// Pass the surface to the video renderer.
MoviePlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, mediasurface);
MoviePlayer.seekTo(Position);
MoviePlayer.setPlayWhenReady(true);
}catch(Exception e){
e.printStackTrace();
FileLog("exception in mediaplayer");
}