gpt4 book ai didi

exoplayer - 从后台线程还是从主 ui 线程使用 exoplayer 更好?

转载 作者:行者123 更新时间:2023-12-04 03:01:50 29 4
gpt4 key购买 nike

为了避免应用程序中的任何 SCSS ,从后台线程使用 exoplayer 还是从主 ui 线程使用它更好?

注意:当我在主 ui 线程中创建一个 simpleExoPlayer 时:

// 1. Create a default TrackSelector
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);

// 2. Create the player
SimpleExoPlayer player =
ExoPlayerFactory.newSimpleInstance(context, trackSelector);

然后花了 90 毫秒 !!它太慢了,我会有几次丢帧,导致我的动画出现抖动。也在做
// Measures bandwidth during playback. Can be null if not required.
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
Util.getUserAgent(context, "yourApplicationName"), bandwidthMeter);
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(mp4VideoUri);
// Prepare the player with the source.
player.prepare(videoSource);

带走了 20 毫秒 !它也慢到慢得多,我将再次丢帧

最佳答案

ExoPlayer 的内部处理线程 - 因此在主(应用程序)线程上调用大多数 API 是安全的。

来自 documentation :

It is recommended that ExoPlayer instances are created and accessed from a single application thread. The application's main thread is ideal. Accessing an instance from multiple threads is discouraged, however if an application does wish to do this then it may do so provided that it ensures accesses are synchronized.



ExoPlayer Threading Model Diagram

关于exoplayer - 从后台线程还是从主 ui 线程使用 exoplayer 更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48498847/

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