您好,我正在学习Exoplayer,所以我开发了一个简单的应用程序,其中从原始文件夹中检索视频。该应用程序在棒棒糖上运行良好,但是当我在Kitkat版本中启动相同的应用程序时,它在媒体控制器上仅显示黑屏并显示视频长度。我试图找到但没有任何有关此问题的信息。提前感谢!
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_margin="20dp"
tools:context=".MainActivity">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Main.java
public class MainActivity extends AppCompatActivity {
private PlayerView playerView;
private SimpleExoPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerView = findViewById(R.id.player_view);
}
@Override
protected void onStart() {
super.onStart();
player = ExoPlayerFactory.newSimpleInstance(this,new DefaultTrackSelector());
playerView.setPlayer(player);
final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(this);
DataSpec dataSpec = new DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.tara));
try {
rawResourceDataSource.open(dataSpec);
DataSource.Factory factory = new DataSource.Factory() {
@Override
public DataSource createDataSource() {
return rawResourceDataSource;
}
};
MediaSource videoSource = new ExtractorMediaSource.Factory(factory).createMediaSource(rawResourceDataSource.getUri());
player.prepare(videoSource);
player.setPlayWhenReady(true);
} catch (RawResourceDataSource.RawResourceDataSourceException e) {
e.printStackTrace();
}
}
}
Logcat错误
E/ACodec: [OMX.google.h264.decoder] ERROR(0x80001001)
E/MediaCodec: Codec reported an error. (omx error 0x80001001, internalError -2147483648)
E/ExoPlayerImplInternal: Internal runtime error.
java.lang.IllegalStateException
at android.media.MediaCodec.dequeueOutputBuffer(Native Method)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1024)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:573)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:518)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
答案 0 :(得分:0)
您可以在onStart方法中尝试此代码部分吗?
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(null);
player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(videoTrackSelectionFactory));
player.setRepeatMode(Player.REPEAT_MODE_ONE);
player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
playerView.setUseController(false);
playerView.setPlayer(player);
player.setPlayWhenReady(true);
final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(this);
DataSpec dataSpec = new DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.tara));
try {
rawResourceDataSource.open(dataSpec);
DataSource.Factory factory = new DataSource.Factory() {
@Override
public DataSource createDataSource() {
return rawResourceDataSource;
}
};
MediaSource videoSource = new ExtractorMediaSource.Factory(factory).createMediaSource(rawResourceDataSource.getUri());
player.prepare(videoSource);
} catch (RawResourceDataSource.RawResourceDataSourceException e) {
e.printStackTrace();
}