PAGE / NUMPAGES
Android使用开发--MP3简单音乐播放器
点击列表会进入播放的Activity,在这个Activity会接收到从前面的Activity传来的数据,在通过这些数据来启动服务来播放音乐,整个过程很简单,需要注意的是我们要接收的数据是哪些内容,还有我们向Service要传什么样的数据,这是根据自己的开发思路和需求来决定的,等一下你们会看到小鬼到底往Service传了些什么东西,然而这些数据到底起什么作用,需要慢慢去体会,因为这是需要一点一点去调试的。
好了,下面贴一下整个Activity的实现代码,主要是播放的各种状态的实现,因为这个音乐播放器并没有完全开发完,所以朋友们需要弄清楚这一点。如果对代码的实现有不清楚的,可以给小鬼留言,小鬼有空一定给大家解答。
效果如下:
代码如下:
package com.anjovo.as.chapter10.exam01。
import java.io.IOException。
import android.media.AudioManager。
import android.media.MediaPlayer。
import android.net.Uri。
import android.os.Bundle。
import android.app.Activity。
import android.content.Intent。
import android.view.ContextMenu。
import android.view.ContextMenu.ContextMenuInfo。
import android.view.Menu。
import android.view.MenuItem。
import android.view.SubMenu。
import android.view.View。
import android.widget.Button。
import android.widget.ImageView。
import android.widget.TextView。
import android.widget.Toast。
public class MusicPlayerActivity extends Activity {
protected static final int REQUEST_CODE = 1。
private Button btnPlay,btnPause,baStop,back。
private ImageView image。
private TextView text。
private MediaPlayer player。
int position = 0。
//声明一个变量判断是否为播放,默认为false
private boolean isPaused = false,Media=false。
@Override
protected void onCreate(Bundle savedInstanceState> {
super.onCreate(savedInstanceState>。
setContentView(R.layout.activity_music_player>。
btnPlay = (Button> findViewById(R.id.bt_play>。
btnPause = (Button> findViewById(R.id.bt_pause>。
baStop = (Button> findViewById(R.id.bt_stop>。
back = (Button> findViewById(R.id.bt_back>。
image = (ImageView> findViewById(R.drawable.ic_launcher>。
text = (TextView> findViewById(R.id.text>。
image = (ImageView> findViewById(R.drawable.fengcun>。
registerForContextMenu(baStop>。//注册,让这个bastop将会启用上下文菜单
text.setText("歌词下载错误!">。
final Intent serintent = new Intent(this,newActivity.class>。
btnPause.setOnClickListener(new View.OnClickListener(> {
@Override
public void onClick(View arg0>