我的歌曲持续时间是15分钟。但我想播放这首歌30分钟。此外,当用户下载PRO版本的应用程序时,该歌曲应播放2小时。我该如何设定时间?
我是Java和Android的新手。
感谢您的帮助。
public class MainActivity extends Activity {
Button start, stop;
// Button btn_play, btn_stop, btn_pause;
MediaPlayer mp;
TextView display, comment;
int length;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
length = 0;
start = (Button) findViewById(R.id.bStart);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mp = MediaPlayer.create(MainActivity.this, R.raw.splahsound);
mp.seekTo(length);
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.reset();
mp.release(); // free up memory
mp = null;
length = 0;
}
});
}
});
stop = (Button) findViewById(R.id.bDur);
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mp != null) {
try {
mp.stop();
mp.reset();
mp.release();
mp = null;
length = 0;
} catch (Exception e) {
Log.d("error", e.toString());
}
}
}
});
}
}