您好,我正在开发一个应用程序,我可以在其中播放具有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();
}
}
}