gpt4 book ai didi

java - 点击播放按钮,应用程序已停止,重新打开

转载 作者:太空宇宙 更新时间:2023-11-04 10:06:38 26 4
gpt4 key购买 nike

我正在使用 exo 播放器创建带有 hls 播放列表的直播电视流媒体应用程序。但是当我点击播放按钮时它停止了。请查看代码并给我建议。

这是 logcat 上显示的错误,但我无法理解: here is the error that shows on logcat, but I can't understand,

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

2.Java代码

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //logcat indicate this line
setContentView(R.layout.activity_streaming);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

url = getIntent().getStringExtra("url");
Uri videoUri = Uri.parse(url);


BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

// Create a default LoadControl
LoadControl loadControl = new DefaultLoadControl();
//Bis. Create a RenderFactory
RenderersFactory renderersFactory = new DefaultRenderersFactory(this);

//Create the player
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
simpleExoPlayerView = new SimpleExoPlayerView(this);
simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view);


//Set media controller
simpleExoPlayerView.setUseController(true);
simpleExoPlayerView.requestFocus();

// Bind the player to the view.
simpleExoPlayerView.setPlayer(player);

//Measures bandwidth during playback. Can be null if not required.
DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();

//Produces DataSource instances through which media data is loaded.
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "PiwikVideoApp"), bandwidthMeterA);

//Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

//FOR LIVE STREAM LINK:
MediaSource videoSource = new HlsMediaSource(videoUri, dataSourceFactory, 1, null, null);
final MediaSource mediaSource = videoSource;


player.prepare(mediaSource);

}

}

最佳答案

如果你想在按下播放按钮时执行某些操作,你必须使用button.SetOnClickListener方法。像这样:

final Button button = findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});

有关此的更多信息,您可以 find here.

关于java - 点击播放按钮,应用程序已停止,重新打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52823099/

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