媒体项目和媒体源之间的不同?

发布于 2025-01-30 02:11:38 字数 1301 浏览 6 评论 0原文

MediaItemMediaSource在Exoplayer中有什么不同,以及如何在最新版本的Exoplayer库(2.17.1)中使用MediaSource?

这是简单的项目如何使用MediaSource而不是MediaItem?

package com.agono.exoplayer;

import ...


public class MainActivity extends AppCompatActivity {
    
    private Context ctx;
    private StyledPlayerView playerView;
    private Button button1;
    private boolean isShowingTrackSelectionDialog;
    private DefaultTrackSelector trackSelector;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String videoUri=getIntent().getStringExtra("url");
        
        trackSelector = new DefaultTrackSelector(/* context= */ this);
        playerView = findViewById(R.id.test);
        button1= findViewById(R.id.button1);
        ExoPlayer player = new ExoPlayer.Builder(this)
        .setTrackSelector(trackSelector)
        .build();
        MediaItem mediaItem = MediaItem.fromUri(videoUri);
        // Attach player to the view.
        playerView.setPlayer(player);
        // Set the media item to be played.
        player.setMediaItem(mediaItem);
        // Prepare the player.
        player.prepare();
        
    }
    
    
    
}

Whats different between MediaItem and MediaSource in exoplayer and how i can use MediaSource in in the latest version of exoplayer library (2.17.1) ?

This is simple project how use MediaSource instead of MediaItem ?

package com.agono.exoplayer;

import ...


public class MainActivity extends AppCompatActivity {
    
    private Context ctx;
    private StyledPlayerView playerView;
    private Button button1;
    private boolean isShowingTrackSelectionDialog;
    private DefaultTrackSelector trackSelector;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String videoUri=getIntent().getStringExtra("url");
        
        trackSelector = new DefaultTrackSelector(/* context= */ this);
        playerView = findViewById(R.id.test);
        button1= findViewById(R.id.button1);
        ExoPlayer player = new ExoPlayer.Builder(this)
        .setTrackSelector(trackSelector)
        .build();
        MediaItem mediaItem = MediaItem.fromUri(videoUri);
        // Attach player to the view.
        playerView.setPlayer(player);
        // Set the media item to be played.
        player.setMediaItem(mediaItem);
        // Prepare the player.
        player.prepare();
        
    }
    
    
    
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2025-02-06 02:11:38

埃法尔文档讨论了这一点:

在超级层次中,每个媒体都由mediaItem表示。但是,在内部,玩家需要MediaSource实例来播放内容。播放器使用MediaSource.Factory。

从媒体项目中创建这些内容

https://exoplayer.dev/media-sources.html

和:

播放列表API基于MediaItems,可以使用MediaItem.builder便利地构建。在播放器内部,媒体项目通过MediaSource将媒体源转换为可玩的MediaSources.factory

如果您只想播放媒体项目或创建播放列表,那么您可能只需要使用MediaItem-最新的Codelabs中有一些好的示例:<<< a href =“ https://developer.android.com/codelabs/exoplayer-intro#0” rel =“ nofollow noreferrer”> https://develoveler.android.com/codelabs/codelabs/exoplayer-intro-intro-intro-intro-intro-intro-intro-intro-intro-intro-intro-intro#0

The ExoPlayer documentation discusses this:

In ExoPlayer every piece of media is represented by a MediaItem. However internally, the player needs MediaSource instances to play the content. The player creates these from media items using a MediaSource.Factory.

(https://exoplayer.dev/media-sources.html)

and:

The playlist API is based on MediaItems, which can be conveniently built using MediaItem.Builder. Inside the player, media items are converted into playable MediaSources by a MediaSource.Factory

If all you want is to play a media item or create a playlist then you probably only need to use MediaItem - there are some good examples in the latest CodeLabs: https://developer.android.com/codelabs/exoplayer-intro#0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文