广播和服务之编写音乐盒代码

广播和服务之编写音乐盒代码
作业要求:参考Musicbox,添加音乐播放的 上一首 和 下一首 控制。
具体功能实现:
1.点击播放键播放音乐,再次点击则暂停,再点击则继续播放,点击停止则终止。
2.点击上下两个键可以进行切歌。
3.播放音乐时显示作者和曲名。
实现页面展示:
1打开:在这里插入图片描述
2播放:在这里插入图片描述
3切歌:在这里插入图片描述
我们这次需要添加切歌功能,因此需要先下载对应切歌的两张图片,我找了半天最后自己做了一个,有需要的可以拖到桌面上,修改文件名称。再添加到drawable里面。
请添加图片描述
请添加图片描述
接着修改xml文件,分别将两张图片插入进去。下面是布局的完整代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

	<ImageButton
		android:id="@+id/last"
		android:layout_width="84dp"
		android:layout_height="match_parent"
		android:background="@drawable/last" />

	<ImageButton
		android:id="@+id/play"
		android:layout_width="wrap_content"
		android:layout_height="match_parent"
		android:src="@drawable/play" />

	<ImageButton
	android:id="@+id/stop" 
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:src="@drawable/stop"/>

	<ImageButton
		android:id="@+id/next"
		android:layout_width="77dp"
		android:layout_height="match_parent"
		android:background="@drawable/next" />
<LinearLayout
	android:orientation="vertical"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
<TextView
	android:id="@+id/title"
	android:layout_width="wrap_content" 
	android:layout_height="wrap_content"
	android:textSize="25sp"
	android:textColor="#9C27B0"
	android:ellipsize="marquee"
	android:layout_weight="1"
	android:marqueeRepeatLimit="marquee_forever"/>
<TextView
	android:id="@+id/author"
	android:textSize="25sp"
	android:gravity="center_vertical"
	android:layout_weight="1"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"/>	    	
</LinearLayout>
</LinearLayout>

接着在mainactivity里连接xml里的last和next,再添加到onclick点击事件的case里,添加监听完整代码如下

package com.example.xr.musicbox;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值