android做一个音乐播放器,制作一个简单的Android版的音乐播放器

音乐播放器是一个非常常见的应用,这篇博客就是介绍如何制作一个简单的音乐播放器,这款音乐播放器具有以下的功能:播放歌曲、暂停播放歌曲、、显示歌曲的总时长、显示歌曲的当前播放时长、调节滑块可以将歌曲调节到任何时间播放、退出音乐播放器

实现效果如下

0818b9ca8b590ca3270a3433284dd417.png

实现方式:

第一步:使用Android Studio创建一个Android工程,并且修改activity_main.xml文件

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.fyt.musicplayer.MainActivity"

android:orientation="vertical">

android:id="@+id/sb"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/tv_progress"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="00:00"/>

android:id="@+id/tv_total"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:text="00:00"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="播放音乐"

android:onClick="play"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="暂停播放"

android:onClick="pausePlay"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="继续播放"

android:onClick="continuePlay"/>

android:layout_width="wrap_content"

android:layout_

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是制作一个基本的音乐播放器项目的步骤: 1. 创建一个新的 Android Studio 项目。在创建项目时,选择“Empty Activity”作为项目模板。 2. 添加依赖项。打开项目的 build.gradle 文件,在 dependencies 中添加以下行: ``` implementation 'com.google.android.material:material:1.1.0' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:support-v4:28.0.0' ``` 3. 在 activity_main.xml 文件中添加 UI 元素。您可以添加一个 RecyclerView 来显示音乐列表,一个 ImageView 来显示专辑封面,一个 SeekBar 来控制进度条,一个 TextView 来显示歌曲名称和艺术家等信息。 4. 创建一个类来表示音乐文件。该类应该包含音乐文件的名称、路径、长度等信息。 5. 创建一个适配器类来处理 RecyclerView 中的音乐文件。该适配器应该能够加载音乐文件的信息,并将其显示在 RecyclerView 中。 6. 创建一个类来处理音乐播放。该类应该包含逻辑来加载音乐文件、播放、暂停、停止等操作。您可以使用 MediaPlayer 类来处理播放逻辑。 7. 在 MainActivity.java 中,初始化音乐播放器和 RecyclerView。您还可以设置 RecyclerView 的布局管理器和适配器。 8. 在 RecyclerView 的项单击事件中,加载并播放音乐文件。 以上是制作一个基本的音乐播放器项目的步骤。您可以根据需求添加更多功能并完善项目。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值