0

您好,我正在开发一个应用程序,我可以在其中播放具有widevine drm 保护的短跑流。我已经阅读了 exoplayer 的示例,但我的需求不同,我会在我的网站上,当点击破折号 url 时,它将开始在 exoplayer 中播放流。我已经成功完成了打开 exoplayer 活动的第一部分,但是我不知道如何在 exoplayer 上运行受 drm 保护的流。

我知道流和 drm 许可证网址。

我正在处理的一个简单代码附在下面。请帮助我提供 drmsessionmanager 等的附加代码。运行流

这是我的代码,它只支持没有 drm 的 mpd:

public class exoplayer2 extends AppCompatActivity { // Variables
    private static final String VIDEO_URI = "http://url.mpd";

    private SimpleExoPlayer player;
    private SimpleExoPlayerView simpleExoPlayerView;
    private Handler mainHandler;
    private TrackSelection.Factory videoTrackSelectionFactory;
    private TrackSelector trackSelector;
    private LoadControl loadControl;
    private DataSource.Factory dataSourceFactory;
    private MediaSource videoSource;
    private Uri uri;
    private String userAgent;
    private static final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

    // Activity onCreate
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_exoplayer);
        simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.player_view);
        userAgent = Util.getUserAgent(this,"SimpleDashExoPlayer");
        createPlayer();
        attachPlayerView();
        preparePlayer();
    }

    // Create TrackSelection Factory, Track Selector, Handler, Load Control, and ExoPlayer Instance
    public void createPlayer(){
        mainHandler = new Handler();
        videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        loadControl = new DefaultLoadControl();
        player = ExoPlayerFactory.newSimpleInstance(this,trackSelector,loadControl);
    }

    // Set player to SimpleExoPlayerView
    public void attachPlayerView(){
        simpleExoPlayerView.setPlayer(player);
    }

    // Build Data Source Factory, Dash Media Source, and Prepare player using videoSource
    public void preparePlayer(){
        uriParse();
        dataSourceFactory = buildDataSourceFactory(bandwidthMeter);
        videoSource = new DashMediaSource(uri,buildDataSourceFactory(null),new DefaultDashChunkSource.Factory(dataSourceFactory),mainHandler,null);
        player.prepare(videoSource);
    }

    // Parse VIDEO_URI and Save at uri variable
    public void uriParse(){
        uri = Uri.parse(VIDEO_URI);
    }

    // Build Data Source Factory using DefaultBandwidthMeter and HttpDataSource.Factory
    private DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
        return new DefaultDataSourceFactory(this, bandwidthMeter, buildHttpDataSourceFactory(bandwidthMeter));
    }

    // Build Http Data Source Factory using DefaultBandwidthMeter
    private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
        return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
    }

    // Activity onStop, player must be release because of memory saving
    @Override
    public void onStop(){
        super.onStop();
        player.release();
    }
}

}
4

1 回答 1

1

要直接启动演示应用程序的 PlayerActivity,需要触发一个 Intent,该 Intent 传递额外的内容以声明设置播放器所需的部分,包括 DRM 参数。

请参阅 ExoPlayer 的开发人员指南,其中记录了所有额外内容

这可以用 adb 测试:

adb shell am start -a com.google.android.exoplayer.demo.action.VIEW \
    -d https://yourdomain.com/sample.mpd  \
    -es drm_license_url [String] \
    -es drm_scheme widevine \
    ....

有关所有选项,请参阅开发人员指南。

initializePlayer请参阅PlayerActivity 方法的源代码,这些 Intent Extras 是如何用于构造和设置 DrmSessionManager 的

于 2018-04-01T17:10:15.393 回答