移动开发第三次作业——Android Studio音乐播放器

Android Studio音乐播放器

一、本项目完成的功能
1.实现音乐播放器的基本功能:播放音乐,暂停音乐,停止音乐,切换到上一首或者下一首音乐
2.实现一些进阶功能:显示专辑封面、歌曲名称、歌手姓名和进度条
3.调整不同控件的位置、大小,使得整个软件界面看起来大方美观

二、代码部分
1.基本代码
在MainActivity中,初始化一些必要的值,例如音乐播放状态和歌曲名称列表。

public class MainActivity extends Activity implements OnClickListener {
   
    // 获取界面中显示歌曲标题、作者文本框
    TextView title, author;
    // 播放/暂停、停止按钮
    ImageButton play, stop;
    // 上一首,下一首按钮
    ImageButton pre, next;
    // 获取封面
    ImageView cover;
    ActivityReceiver activityReceiver;

    public static SeekBar audioSeekBar = null;
    public static final String CTL_ACTION =
            "org.ly.action.CTL_ACTION";
    public static final String UPDATE_ACTION =
            "org.ly.action.UPDATE_ACTION";
    // 定义音乐的播放状态,0x11代表没有播放;0x12代表正在播放;0x13代表暂停
    int status = 0x11;
    String[] titleStrs = new String[] {
    "Ride", "Intentions", "thank u, next" };
    String[] authorStrs = new String[] {
    "Lana Del Rey", "Justin Bieber", "Ariana Grande" };
    Integer[] covers = new Integer[] {
    R.drawable.lana, R.drawable.bieber, R.drawable.ariana};

在onCreate函数中,获取页面中各种控件,添加监听器。

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

        // 获取程序界面界面中的两个按钮
        play = (ImageButton) this.findViewById(R.id.play);
        stop = (ImageButton) this.findViewById(R.id.stop);
        title = (TextView) findViewById(R.id.title);
        author = (TextView) findViewById(R.id.author);
        cover 
  • 13
    点赞
  • 256
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值