android音乐播放器的常用操作
jopen
11年前
1. [代码]变量申明
01 | /*变量声明*/ |
02 | private ImageButton playBtn = null ; //播放、暂停 |
03 | private ImageButton latestBtn = null ; //上一首 |
04 | private ImageButton nextButton = null ; //下一首 |
05 | private ImageButton forwardBtn = null ; //快进 |
06 | private ImageButton rewindBtn = null ; //快退 |
07 | private TextView playtime = null ; //已播放时间 |
08 | private TextView durationTime = null ; //歌曲时间 |
09 | private SeekBar seekbar = null ; //歌曲进度 |
10 | private Handler handler = null ; //用于进度条 |
11 | private Handler fHandler = null ; //用于快进 |
12 | private int currentPosition; //当前播放位置 |
2. [代码]获得上一个activity传来的数据
01 | @Override |
02 | protected void onCreate(Bundle savedInstanceState) { |
03 | super .onCreate(savedInstanceState); |
04 | setContentView(R.layout.play); |
05 | Intent intent = this .getIntent(); |
06 | Bundle bundle = intent.getExtras(); |
07 | _ids = bundle.getIntArray( "_ids" ); //获得保存音乐文件_ID的数组 |
08 | position = bundle.getInt( "position" ); //获得应该播放的音乐的号数,既播放第几首 |
09 | //代码未完,见下面的代码 |
10 | } |
3. [代码]初始化控件
1 | playtime = (TextView)findViewById(R.id.playtime); //显示已经播放的时间 |
2 | durationTime = (TextView)findViewById(R.id.duration); //显示歌曲总时间 |
3 | playBtn = (ImageButton)findViewById(R.id.playBtn); //开始播放、暂停播放按钮 |
4 | latestBtn = (ImageButton)findViewById(R.id.latestBtn); //播放上一首按钮 |
5 | nextButton = (ImageButton)findViewById(R.id.nextBtn); //播放下一首按钮 |
6 | forwardBtn = (ImageButton)findViewById(R.id.forwardBtn); //快进按钮 |
7 | rewindBtn = (ImageButton)findViewById(R.id.rewindBtn); //快退按钮 |
8 | seekbar = (SeekBar)findViewById(R.id.seekbar); //播放进度条 |