gpt4 book ai didi

Android Exoplayer : Is it possible to use exoplayer to stream video from firebase storage?

转载 作者:行者123 更新时间:2023-12-04 15:56:19 28 4
gpt4 key购买 nike

在 android 中有一个名为 的库。 Exoplayer 这与从给定 url 流式传输视频有关。

现在根据this firebase 不支持视频流,尽管您可以将 uri 从 url 传递到 videoview(它实际上会流式传输)。

问题:

exoplayer 可以用于从 firebase 存储流式传输视频吗?

为什么即使可以通过 videoview 完成,也无法进行 firebase 状态流式传输?

最佳答案

是的,它可以从 firebase 流式传输视频。

首先在你的 xml 文件中创建一个 exoplayer

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="0sp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

我已将高度设置为 0 因为我稍后将以编程方式修复高度

然后在您的 Activity 中将简单的 SimpleExoPlayer 声明为播放器。
 SimpleExoPlayer player;

然后在你按照这些步骤
//declare your PlayerView 

final PlayerView playerView = mview.findViewById(R.id.video_view);

//your database ref

final StorageReference storageReference =
FirebaseStorage.getInstance().getReference("/Post_Video/"+ video + ".mp4");


player = ExoPlayerFactory.newSimpleInstance(MainActivity.this);
playerView.setPlayer(player);

playerView.setVisibility(View.VISIBLE);

playerView.getLayoutParams().height=550;
playerView.getLayoutParams().width=950;



storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {


BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(MainActivity.this).build();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
ExoPlayer exoPlayer = (SimpleExoPlayer) ExoPlayerFactory.newSimpleInstance(MainActivity.this);
Uri video = Uri.parse(uri.toString());
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("video");
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(video,dataSourceFactory,extractorsFactory,null,null);
playerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(false);




}
});

关于Android Exoplayer : Is it possible to use exoplayer to stream video from firebase storage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51463115/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com