源码地址:https://github.com/yeaper/MusicPlayer
因项目需要,实现的功能类似QQ音乐播放界面
使用 kotlin 代替 Java
主要功能:
1、播放、暂停音乐
2、自动、手动设置进度条,并且同步播放音乐
3、开启、暂停、停止匀速旋转的动画
先看效果图:
1、布局文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context="cc.redhome.hduin.view.discover.hduradio.programalbum.ProgramPlayActivity">
<ImageView
android:id="@+id/programPlayHeaderBg"
android:layout_width="match_parent"
android:layout_height="240dp"
android:background="@drawable/hdu_radio_header_bg"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/programPlayLyric"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_marginTop="80dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:lineSpacingMultiplier="1.5"
android:textColor="@color/white"
android:textSize="17sp"/>
<FrameLayout
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp">
<com.pkmmte.view.CircularImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/developer_fat"
app:shadow="true"
app:border="true"
app:border_width="9dp"
app:border_color="@color/record_border_bg_color" />
<com.pkmmte.view.CircularImageView
android:id="@+id/programPlayRecordImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="6dp"/>
</FrameLayout>
<TextView
android:id="@+id/programPlayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textColor="@color/primaryTextDark"
android:textSize="17sp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/programPlayAnchor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"