我正在与exoplayer合作,现在我正在尝试下载audio.i已经完成了创建下载管理器的工作,现在我在传递参数时遇到错误,请参见图片...
这里是代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exoplayer);
thumb = findViewById(R.id.thumb);
head = findViewById(R.id.head);
String image = getIntent().getStringExtra("image");
url = getIntent().getStringExtra("url");
String title = getIntent().getStringExtra("title");
head.setText(title);
Glide.with(this).asBitmap().load(image).into(thumb);
//download
head.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ProgressiveDownloadAction progressiveDownloadAction = new ProgressiveDownloadAction(url,false,null, null);//here where i am getting error
DownloadService.startWithAction(exoplayer.this, AudioDownloadService.class, null,false);
}
});
initializeplayer();
}
public void initializeplayer(){
playerView = findViewById(R.id.exo);
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this);
playerView.setPlayer(simpleExoPlayer);
DataSource.Factory datasourcefactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "appname"));
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(DownloadUtil.getCache(this),datasourcefactory);
ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource();//
MediaSource mediaSource = new ExtractorMediaSource.Factory(cacheDataSourceFactory)//it was datasourcefactory
.createMediaSource(Uri.parse(url));
concatenatingMediaSource.addMediaSource(mediaSource);//
simpleExoPlayer.prepare(mediaSource);
simpleExoPlayer.setPlayWhenReady(true);
}
现在那里需要什么参数。如果有人可以,请帮助我。
编辑:通过Uri.parse(url)后收到此错误...
java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'byte [] com.google.android.exoplayer2.offline.DownloadAction.toByteArray()'在com.google.android.exoplayer2.offline.DownloadService.buildAddActionIntent(DownloadService.java:173)在com.google.android.exoplayer2.offline.DownloadService.startWithAction(DownloadService.java:190)在com.example.project.exoplayer $ 1.onClick(exoplayer.java:60)在android.view.View.performClick(View.java:6294)在android.view.View $ PerformClick.run(View.java:24770)在android.os.Handler.handleCallback(Handler.java:790)在android.os.Handler.dispatchMessage(Handler.java:99)在android.os.Looper.loop(Looper.java:164)在android.app.ActivityThread.main(ActivityThread.java:6499)在java.lang.reflect.Method.invoke(本机方法)在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:442)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
在您的ProgressiveDownloadAction构造函数中,使用Uri.parse(url)
代替url