3
我已經在我的Android應用程序中使用以下代碼實現了ExoPlayer。根據演示器演示應用程序中視頻的寬高比更改表面視圖的寬高比
String versionName;
try {
String packageName = getPackageName();
PackageInfo info = getPackageManager().getPackageInfo(packageName, 0);
versionName = info.versionName;
} catch (PackageManager.NameNotFoundException e) {
versionName = "?";
}
player = ExoPlayer.Factory.newInstance(2);
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
DataSource dataSource = new DefaultUriDataSource(this, null, versionName);
MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser();
UriDataSource manifestDataSource = new DefaultUriDataSource(this, versionName);
ManifestFetcher<MediaPresentationDescription> manifestFetcher = new ManifestFetcher<>(passedWorkoutObject.workoutMediaURL, manifestDataSource, parser);
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
Uri.parse(VIDEO_URL), dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(
this, sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
player.prepare(videoRenderer, audioRenderer);
player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
player.setPlayWhenReady(true);
control = new PlayerControl(player);
但問題是我需要播放所有方面比率的視頻。如何調整surfaceView以適應視頻的大小而不是其他方式?
你解決了這個問題嗎? –