Android初级,MediaPlayer播放音乐,进度条滑动及唱片转动功能实现

最近在做仿网易云音乐播放器的实训项目,学习完后写此博客,一方面巩固自己理解,一方面方便各位浏览。
读完本文你将了解到:

  • 如何利用MediaPlayer播放音乐
  • 如何设置音乐进度条并实现自动滚动及手动定位
  • 如何实现唱片转动功能

1.效果图

这里写图片描述
这里写图片描述

2.代码如下

Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical">
//设置背景图片
    <ImageView
        android:id="@+id/listen_background_iv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@mipmap/img1" />

    <RelativeLayout
        android:id="@+id/listen_rl"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_weight="1">
//设置返回按钮图片
        <ImageView
            android:id="@+id/listen_back1_iv"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:src="@mipmap/back1" />
//设置歌曲名
        <TextView
            android:id="@+id/listen_title_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="8dp"
            android:layout_toRightOf="@id/listen_back1_iv"
            android:text="成都"
            android:textColor="#f9f7f7"
            android:textSize="20sp" />
//设置歌手名
        <TextView
            android:id="@+id/listen_artist_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@id/listen_title_tv"
            android:layout_below="@id/listen_title_tv"
            android:layout_marginTop="5dp"
            android:text="赵雷-"
            android:textColor="#aeabab"
            android:textSize="15sp" />
//设置专辑名
        <TextView
            android:id="@+id/listen_album_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@id/listen_artist_tv"
            android:layout_toRightOf="@id/listen_artist_tv"
            android:text="成都"
            android:textColor="#aeabab"
            android:textSize="15sp" />
//设置“分享”按钮(本代码中未实现)
        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="15dp"
            android:src="@mipmap/share" />
//设置布局间的线
        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_below="@id/listen_artist_tv"
            android:background="#bababa" />
    </RelativeLayout>

//设置唱片圆盘
    <ImageView
        android:id="@+id/listen_changpian_img"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"

        android:src="@mipmap/play_page_disc" />
//设置圆盘上的指针
    <ImageView
        android:id="@+id/listen_zhizhen_iv"
        android:layout_width="100dp"
        android:layout_height="150dp"
      
  • 11
    点赞
  • 67
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值