我找到了一些用于在线媒体播放器的搜索栏代码:
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// remove message Handler from updating progress bar
mHandler.removeCallbacks(mUpdateTimeTask);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.removeCallbacks(mUpdateTimeTask);
int totalDuration = mp.getDuration();
int currentPosition = utils.progressToTimer(seekBar.getProgress(), totalDuration);
// forward or backward to certain seconds
mp.seekTo(currentPosition);
// update timer progress again
updateProgressBar();
}
由于 Override,我收到一个错误,告诉我他们必须重写或实现超类型方法。当我删除它们时,我的代码会编译并运行,但搜索栏与播放的音乐没有关联,因为我可以移动它但音乐继续播放。
谢谢。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mp = new MediaPlayer();
seekBar = (SeekBar) findViewById(R.id.seekBar1);
seekBar.setOnSeekBarChangeListener(this); //this line causes an error
try {
mp.setDataSource(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getPath() + "/SpaceJam.mp3");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onStart(){
super.onStart();
btnPlay = (ImageButton) findViewById(R.id.play_pause);
btnStop = (ImageButton) findViewById(R.id.stop);
songTitleLabel = (TextView) findViewById(R.id.songname);
songTitleArtist = (TextView) findViewById(R.id.artist);
songCurrentDurationLabel = (TextView) findViewById(R.id.current);
songTotalDurationLabel = (TextView) findViewById(R.id.total);
albumArt = (ImageView) findViewById(R.id.albumArt);
res = getResources().getDrawable(R.drawable.album_art);
utils = new Utilities();
. . .
}