gpt4 book ai didi

java - 方法不会重写或实现父类(super class)型 ExoPlayer 中的方法

转载 作者:行者123 更新时间:2023-12-01 17:53:07 27 4
gpt4 key购买 nike

我到处寻找,但找不到该错误的解决方案。我知道 StackOverflow 中有很多与该主题相关的问题,但我不明白。我正在使用 ExoPlayer。

error: method does not override or implement a method from a supertype

Android Studio 突出显示了 8 个@Override

AdaptiveMediaSourceEventListener的方法带有红色下划线。

onTimelineChanged 带有红色下划线

onPositionDiscontinuity 带有红色下划线

主要 Activity :

package rusiptv.net;

//http://mos.rusiptv.net:8080/live/@celalsonat/784512/94815.m3u8

public class MainActivity extends AppCompatActivity implements ExoPlayer.EventListener {

private SimpleExoPlayerView simpleExoPlayerView;
private String hlsVideoUri = "http://mos.rusiptv.net:8080/live/@celalsonat/784512/94815.m3u8";
private SimpleExoPlayer player;
private ProgressBar progressBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// 1. Create a default TrackSelector
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new
AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

// 2. Create a default LoadControl
LoadControl loadControl = new DefaultLoadControl();

// 3. Create the player
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.player_view);
simpleExoPlayerView.setPlayer(player);

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

// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "Exo2"), defaultBandwidthMeter);
// Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
// This is the MediaSource representing the media to be played.
HlsMediaSource hlsMediaSource = new HlsMediaSource(Uri.parse(hlsVideoUri), dataSourceFactory, mainHandler, new AdaptiveMediaSourceEventListener(){

@Override
public void onLoadStarted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs){

}

@Override
public void onLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format
trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {

}

@Override
public void onLoadCanceled(DataSpec dataSpec, int dataType, int trackType, Format
trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {

}

@Override
public void onLoadError(DataSpec dataSpec, int dataType, int trackType, Format
trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded,
IOException error, boolean wasCanceled) {

}

@Override
public void onUpstreamDiscarded(int trackType, long mediaStartTimeMs, long
mediaEndTimeMs) {

}

@Override
public void onDownstreamFormatChanged(int trackType, Format trackFormat, int
trackSelectionReason, Object trackSelectionData, long mediaTimeMs) {

}
});

player.addListener(this);
player.prepare(hlsMediaSource);
simpleExoPlayerView.requestFocus();
player.setPlayWhenReady(true);

progressBar = (ProgressBar) findViewById(R.id.progressBar);
}
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {

}

@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {

}

@Override
public void onLoadingChanged(boolean isLoading) {

}

@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

switch (playbackState) {
case Player.STATE_BUFFERING:
//You can use progress dialog to show user that video is preparing or buffering so
please wait
progressBar.setVisibility(View.VISIBLE);
break;
case Player.STATE_IDLE:
//idle state
break;
case Player.STATE_READY:
// dismiss your dialog here because our video is ready to play now
progressBar.setVisibility(View.GONE);
break;
case Player.STATE_ENDED:
// do your processing after ending of video
break;
}
}

@Override
public void onPlayerError(ExoPlaybackException error) {

AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
adb.setTitle("Could not able to stream video");
adb.setMessage("It seems that something is going wrong.\nPlease try again.");
adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish(); // take out user from this activity. you can skip this
}
});
AlertDialog ad = adb.create();
ad.show();
}

@Override
public void onPositionDiscontinuity() {

}

@Override
protected void onPause() {
super.onPause();
if (player != null) {
player.setPlayWhenReady(false); //to pause a video because now our video player is not in
focus
}
}

@Override
protected void onDestroy() {
super.onDestroy();
player.release();
}


}

最佳答案

使用:

@Override
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
}


@Override
public void onPositionDiscontinuity(int reason)
{

}

for more infos

关于java - 方法不会重写或实现父类(super class)型 ExoPlayer 中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60762236/

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