Android 音乐播放器--界面的实现(一)

暑假学了十几天安卓还是感觉很陌生,感觉是时候写个小项目巩固下了,于是就有了这个简单的音乐播放器,

界面是模仿的网易云音乐,图标的资源也是从网易云音乐取的,效果如图:

已实现功能:

  • 选择播放模式:循环 顺序 随机
  • 音乐控制:播放 暂停 下一曲 上一曲 专辑图片的显示

未实现功能:

  • 歌词的显示
  • 歌曲搜索
  • 网络歌曲: 因为开始以为qq音乐之类的提供了api..后来发现是我想多了,所以这个功能多半实现不了了

标题栏

标题栏我把它单独写了个文件,在需要使用它的地方只需要写<include layout="@layout/title"/>就可以复用了

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     android:layout_width="match_parent"
  4     android:layout_height="55dp"
  5     android:background="#d5050504">
  6     <LinearLayout
  7         android:layout_width="0dp"
  8         android:layout_height="match_parent"
  9         android:layout_weight="1">
 10
 11         <RelativeLayout
 12             android:layout_width="0dp"
 13             android:layout_height="match_parent"
 14             android:layout_weight="1"
 15             android:id="@+id/list_layout">
 16             <LinearLayout
 17                 android:layout_width="match_parent"
 18                 android:layout_height="wrap_content"
 19                 android:orientation="vertical">
 20                 <ImageView
 21                     android:src="@drawable/songlist"
 22                     android:id="@+id/list_image"
 23                     android:layout_width="40dp"
 24                     android:layout_height="40dp"
 25                     android:layout_gravity="center_horizontal"/>
 26                 <TextView
 27                     android:id="@+id/list_text"
 28                     android:layout_width="wrap_content"
 29                     android:layout_height="wrap_content"
 30                     android:layout_gravity="center_horizontal"
 31                     android:textSize="12dp"
 32                     android:text="本地歌曲"
 33                     android:textColor="#84f8f9ef" />
 34             </LinearLayout>
 35         </RelativeLayout>
 36
 37         <RelativeLayout
 38             android:layout_width="0dp"
 39             android:layout_height="match_parent"
 40             android:layout_weight="1"
 41             android:id="@+id/play_layout">
 42             <LinearLayout
 43                 android:layout_width="match_parent"
 44                 android:layout_height="wrap_content"
 45                 android:orientation="vertical">
 46                 <ImageView
 47                     android:src="@drawable/netlist"
 48                     android:id="@+id/play_image"
 49                     android:layout_width="40dp"
 50                     android:layout_height="40dp"
 51                     android:layout_gravity="center_horizontal"/>
 52                 <TextView
 53                     android:id="@+id/play_text"
 54                     android:layout_width="wrap_content"
 55                     android:layout_height="wrap_content"
 56                     android:layout_gravity="center_horizontal"
 57                     android:textSize="12dp"
 58                     android:text="网络歌曲"
 59                     android:textColor="#84f8f9ef" />
 60             </LinearLayout>
 61         </RelativeLayout>
 62         <RelativeLayout
 63             android:layout_width="0dp"
 64             android:layout_height="match_parent"
 65             android:layout_weight="1"
 66             android:id="@+id/about_layout">
 67             <LinearLayout
 68                 android:layout_width="match_parent"
 69                 android:layout_height="wrap_content"
 70                 android:orientation="vertical">
 71                 <ImageView
 72                     android:src="@drawable/about"
 73                     android:id="@+id/about_image"
 74                     android:layout_width="40dp"
 75                     android:layout_height="40dp"
 76                     android:layout_gravity="center_horizontal"/>
 77                 <TextView
 78                     android:id="@+id/about_text"
 79                     android:layout_width="wrap_content"
 80                     android:layout_height="wrap_content"
 81                     android:layout_gravity="center_horizontal"
 82                     android:textSize="12dp"
 83                     android:text="哦哦哦"
 84                     android:textColor="#84f8f9ef" />
 85             </LinearLayout>
 86         </RelativeLayout>
 87     </LinearLayout>
 88
 89     <LinearLayout
 90         android:layout_width="0dp"
 91         android:layout_height="match_parent"
 92         android:layout_weight="1">
 93         <RelativeLayout
 94             android:layout_width="match_parent"
 95             android:layout_height="match_parent">
 96             <ImageView
 97                 android:layout_alignParentRight="true"
 98                 android:layout_centerVertical="true"
 99                 android:id="@+id/setting_image"
100                 android:src="@drawable/music_icn_more_prs"
101                 android:scaleType="center"
102                 android:layout_width="40dp"
103                 android:layout_height="40dp" />
104             <ImageView
105                 android:layout_toLeftOf="@id/setting_image"
106                 android:layout_centerVertical="true"
107                 android:id="@+id/search_image"
108                 android:src="@drawable/search"
109                 android:layout_width="40dp"
110                 android:layout_height="40dp" />
111         </RelativeLayout>
112     </LinearLayout>
113
114
115 </LinearLayout>

activity_Main

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
 3     android:layout_height="match_parent"
 4     android:orientation="vertical"
 5     tools:context=".MainActivity">
 6
 7     <include layout="@layout/title"/>
 8     <!--使用碎片来实现标签切换-->
 9     <FrameLayout
10         android:id="@+id/content"
11         android:layout_width="match_parent"
12         android:layout_height="0dp"
13         android:layout_weight="1">
14
15     </FrameLayout>
16
17     <!--分割条-->
18     <ImageView
19         android:layout_width="match_parent"
20         android:layout_height="1dp"
21         android:background="#CFCFCF"/>
22     <!--底部播放界面-->
23     <LinearLayout
24         android:layout_width="match_parent"
25         android:layout_height="45dp"
26         android:orientation="horizontal"
27         android:background="#EEEEEE">
28         <LinearLayout
29             android:id="@+id/botton_playing_board"
30             android:layout_width="0dp"
31             android:layout_height="match_parent"
32             android:layout_weight="1">
33             <ImageView
34                 android:id="@+id/botton_song_image"
35
36                 android:layout_width="45dp"
37                 android:layout_height="45dp"
38                 android:src="@drawable/default_album"/>
39             <LinearLayout
40                 android:layout_marginLeft="8dp"
41                 android:layout_weight="1"
42                 android:orientation="vertical"
43                 android:layout_width="wrap_content"
44                 android:layout_height="match_parent">
45                 <TextView
46                     android:id="@+id/main_title"
47                     android:layout_width="match_parent"
48                     android:layout_height="27dp"
49                     android:textSize="21dp"
50                     android:gravity="center_vertical"
51                     android:maxLines="1"
52                     android:layout_gravity="center_vertical"/>
53                 <TextView
54                     android:id="@+id/main_artist"
55                     android:layout_width="match_parent"
56                     android:layout_height="18dp"
57                     android:textSize="13dp"
58                     android:maxLines="1"
59                     android:layout_gravity="center_vertical"
60                     android:gravity="center_vertical"/>
61             </LinearLayout>
62         </LinearLayout>
63
64         <ImageView
65             android:id="@+id/mainPlayPause"
66             android:layout_width="45dp"
67             android:layout_height="match_parent"
68             android:src="@drawable/note_btn_play_white"/>
69         <ImageView
70             android:id="@+id/mainLastSong"
71             android:layout_marginLeft="8dp"
72             android:layout_width="45dp"
73             android:layout_height="match_parent"
74             android:src="@drawable/note_btn_next_white"/>
75         </LinearLayout>
76
77 </LinearLayout>

播放界面activity_playing

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.agmcs.musicplayer.PlayingActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:background="#d5050504">
        <LinearLayout
            android:id="@+id/playing_title_board"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <ImageView
                android:id="@+id/playing_back"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_gravity="center"
                android:src="@drawable/back"/>
            <LinearLayout
                android:layout_marginLeft="8dp"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="match_parent">
                <TextView
                    android:id="@+id/playing_title"
                    android:layout_width="match_parent"
                    android:layout_height="30dp"
                    android:textSize="25dp"
                    android:gravity="center_vertical"
                    android:maxLines="1"
                    android:layout_gravity="center_vertical"
                    android:textColor="#84f8f9ef" />
                <TextView
                    android:id="@+id/playing_artist"
                    android:layout_width="match_parent"
                    android:layout_height="24dp"
                    android:textSize="18dp"
                    android:maxLines="1"
                    android:layout_gravity="center_vertical"
                    android:gravity="center_vertical"
                    android:textColor="#84f8f9ef" />
            </LinearLayout>
        </LinearLayout>
        <ImageView
            android:layout_gravity="center"
            android:layout_width="40dp"
            android:layout_height="40dp"/>

        </LinearLayout>

    <FrameLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:background="#333333"
        android:layout_height="0dp">
        <ImageView
            android:id="@+id/playing_image"
            android:layout_width="match_parent"
            android:alpha="0.8"
            android:layout_height="match_parent" />
        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="match_parent">
            <ScrollView
                android:layout_weight="1"
                android:overScrollMode="never"
                android:scrollbars="none"
                android:layout_margin="5dp"
                android:layout_width="match_parent"
                android:layout_height="0dp">
                <TextView
                    android:id="@+id/playing_lyrics"
                    android:overScrollMode="always"
                    android:gravity="center_horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textSize="25dp"
                    android:textColor="#b1b1b1"/>
            </ScrollView>
            <LinearLayout
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="120dp">

                <SeekBar
                    android:id="@+id/seek_bar"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:layout_width="match_parent"
                    android:layout_height="30dp" />
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_weight="1"
                    android:layout_marginBottom="10dp"
                    android:layout_width="match_parent"
                    android:layout_height="0dp">
                    <ImageView
                        android:id="@+id/playing_mode"
                        android:layout_weight="1"
                        android:src="@drawable/play_btn_loop"
                        android:layout_width="0dp"
                        android:layout_height="match_parent" />
                    <ImageView
                        android:id="@+id/playing_prev"
                        android:layout_weight="1"
                        android:src="@drawable/play_btn_prew"
                        android:layout_width="0dp"
                        android:layout_height="match_parent" />
                    <ImageView
                        android:id="@+id/playing_play_pause"
                        android:layout_weight="1"
                        android:src="@drawable/play_btn_play"
                        android:layout_width="0dp"
                        android:layout_height="match_parent" />
                    <ImageView
                        android:id="@+id/playing_next"
                        android:layout_weight="1"
                        android:src="@drawable/play_btn_next"
                        android:layout_width="0dp"
                        android:layout_height="match_parent" />
                    <ImageView
                        android:id="@+id/playing_audio"
                        android:layout_weight="1"
                        android:src="@drawable/music_icn_more_prs"
                        android:layout_width="0dp"
                        android:scaleType="center"
                        android:layout_height="match_parent" />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
        </FrameLayout>
</LinearLayout>

fragment_music_list 碎片

listview用来显示播放列表

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.agmcs.musicplayer.MusicListFrag">

    <ListView
        android:id="@+id/music_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        </ListView>

</FrameLayout>

fragment_about碎片

什么都没有...

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.example.agmcs.musicplayer.AboutFrag">

    <!-- TODO: Update blank fragment layout -->
    <TextView android:layout_width="match_parent" android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment" />

</FrameLayout>

fragment_net_list碎片

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.example.agmcs.musicplayer.NetListFrag">

    <!-- TODO: Update blank fragment layout -->
    <TextView android:layout_width="match_parent" android:layout_height="match_parent"
        android:text="NetList" />
</FrameLayout>
时间: 2024-08-26 04:23:16

Android 音乐播放器--界面的实现(一)的相关文章

自编Win8风格Android音乐播放器应用源码(单机版)

用闲暇的两天时间,研究编写了一个类Win8风格的android音乐播放器,实现了大部分基本功能.下面看具体描述: 基本实现功能:注意事项:Android系统版本须在2.2以上,保证手机安装有SD卡(部分图标来至qq音乐和百度音乐)界面组成:欢迎界面:淡入,随机图片 由于代码不少,所以在这里贴出来也不太现实,嗯,那就上链结吧,请各位到源码天堂网站上下载吧: http://code.662p.com/view/4733.html 主界面:4个tab标签页,4宫格: --  歌曲列表界面:从sd卡中扫

iOS 简单音乐播放器 界面搭建

如图搭建一个音乐播放器界面,具备以下几个简单功能: 1,界面协调,整洁. 2,点击播放,控制进度条. 3.三收藏歌曲,点击收藏,心形收藏标志颜色加深. 4,左右按钮,切换歌曲图片和标题. 5,点击中间图片,隐藏所有按钮,仅显示蓝色背景. 设计的整体思路: 1.在搭建界面的时候,为了整洁和方便后续的功能的添加,需要将整个的界面划分为几个部分: ①:最上面的一行包括:一个返回按钮.一个歌曲名称.一个收藏按钮: ②:第二行:一个slider控件.两侧是当前的歌曲播放进度和歌曲的总时长--两个lable

android音乐播放器开发教程

android音乐播放器开发教程 android音乐播放器开发教程,布布扣,bubuko.com

[Android]音乐播放器总结

1. MediaPlayer要播放的文件主要包括3个来源:a. 用户在应用中事先自带的resource资源例如:mp = MediaPlayer.create(this, R.raw.test);b. 存储在SD卡或其他文件路径下的媒体文件例如:mp.setDataSource("/sdcard/test.mp3");c. 网络上的媒体文件例如:mp.setDataSource("http://www.citynorth.cn/music/confucius.mp3"

android音乐播放器开发 SweetMusicPlayer 智能负载直插式歌词

在一份书面的使用MediaPlayer播放音乐, http://blog.csdn.net/huweigoodboy/article/details/39862773.假设没有本地歌词怎么办?如今来将一下载入在线歌词.好了,还是用那张图. 在实现这个功能的时候,lz尝试过baidu api,歌词迷api,后来选用了歌词迷api.尽管还是资源不全.并且还有非常多错误. 特别头疼的是有时候歌词竟然不分行.解析起来简直难受. 歌词迷api歌词查询地址:http://geci.me/api/lyric/

android音乐播放器源码

最近研究android音乐播放器,弄了一个,还可以,可以实现播放.暂停.拖动进度等功能. 源码地址:http://download.csdn.net/detail/a358763471/8728855

Android音乐播放器源码(歌词.均衡器.收藏.qq5.0菜单.通知)

Android音乐播放器(歌词.均衡器.收藏.qq5.0菜单.通知) 一款Android音乐播放器源码,基本功能都实现了 qq5.0菜单(歌词.均衡器.收藏.qq5.0菜单.通知) 只有向右滑动出现,菜单键和指定按钮都还没有添加. 下载地址:http://www.devstore.cn/code/info/1144.html 运行截图:     热门源码下载: 高仿京东商城 Android快速开发不可或缺的11个工具类 Android快速开发框架LoonAndroid Android应用源码比较

如何写一个正经的Android音乐播放器 一

以前写过很多次音乐播放器,但是总有一些问题出现,例如: 1,音乐长时间播放问题(即便是放在service中去播放,依然会被杀死): 2,音乐的播放进度如何掌握?(如何利用mediaplayer.getCurrentPosition()来有效的通知界面变更进度?): 3,在我以往的经验中,音乐播放完毕下一曲时候,经常出现当前音乐播放还差几秒钟的时候就下一曲了的情况. 从网上找到教程中,通常都是一个播放器的demo,简单的直接把MediaPlayer放在了一个Activity中去操作,稍有良心的教程

android音乐播放器的竞品分析

迄今为止最长的一篇博客,各位看官笑纳~~ 本次分析基于android平台,选取了几款我体验过的播放器进行比较分析.主要分为两类,一类是大而全的,功能全面,可满足用户管理歌曲.导入导出歌单等多方面需求,不仅仅是听歌,另一类是小而简的,操作简单,让用户专注听歌. 1. QQ音乐          版本:5.2.1.15 特点:这款产品在PC端就有庞大的用户基础,有一定的用户粘性,手机端是web端的延伸.其性能和体验都很不错,1. 曲库强大,可选不同播放音效和音质:2. 独具Qplay功能,可将手机里