毕业设计- 基于Android的网络音乐播放器
时间:2022-03-08 07:36:05 阅读数:58,417人阅读
作者:Android学习小站
版权声明:转载请注明出处,谢谢!
—— 如果在这里退缩的话,那过去那些重要的誓言,约定,全部都会消失不见,而我再也回不到这里了。
项目介绍
本系统支持网络音乐和本地音乐播放,网络音乐使用okhttp3获取在线酷狗API经过Json解析,本地音乐会自动扫描手机上全部音乐文件
1. 本地音乐 首次进入系统需要去扫描手机上的音乐文件,扫描完成在首页本地列表中显示,点击歌曲即可播放,歌曲可标记为喜欢,相应的在最近播放列表、喜欢列表中显示;
2. 网络音乐 此功能需要网络环境下使用,点击排行即可获取酷狗音乐排行榜,可查看音乐榜所有歌曲,点击歌曲即可播放,可搜索网络歌曲;
3. 播放音乐 点击页面下方播放栏即可跳到播放详情页面,可查看歌手海报图、实时歌词,歌词具有滚动效果,可设置音乐播放模式如顺序播放、随机播放,可快捷上一首、下一首、暂停播放等,点击更多按钮可在线搜索歌词,设置歌词字体颜色、大小等;
项目截图
实现原理
布局文件activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <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:background="#000" android:orientation="vertical" tools:context="com.anxiaobang.music.ui.MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.anxiaobang.music.widget.SlidingMenuLayout android:id="@+id/slidingMenuLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/main_container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include android:id="@+id/title" layout="@layout/layout_main_title" android:layout_width="match_parent" android:layout_height="@dimen/title_height"/> <androidx.viewpager.widget.ViewPager android:id="@+id/viewpage" android:layout_width="match_parent" android:layout_height="match_parent" android:overScrollMode="never" /> </LinearLayout> </com.anxiaobang.music.widget.SlidingMenuLayout> <ViewStub android:id="@+id/viewstub_main_pop" android:layout_width="match_parent" android:layout_height="match_parent" android:layout="@layout/layout_main_pop" android:paddingBottom="@dimen/player_height"/> <LinearLayout android:id="@+id/playerBarParent" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="vertical"> <com.anxiaobang.music.widget.DividerView android:id="@+id/divider" android:layout_width="match_parent" android:layout_height="2dp" /> <com.anxiaobang.music.widget.SwipeOutLayout android:id="@+id/playerBar" android:layout_width="match_parent" android:layout_height="@dimen/player_height"/> </LinearLayout> </RelativeLayout> </LinearLayout>
/** * 获取排行里面的歌曲列表 * * @param rankid * @param ranktype * @param page * @param pagesize * @return * @throws Exception * @author santiago * @date 2021年7月2日 */ public static HttpResult rankSong(HPApplication hPApplication, Context context, String rankid, String ranktype, String page, String pagesize) { HttpResult httpResult = new HttpResult(); if (!NetUtil.isNetworkAvailable(context)) { httpResult.setStatus(HttpResult.STATUS_NONET); httpResult.setErrorMsg("当前网络不可用"); return httpResult; } if (hPApplication.isWifi()) { if (!NetUtil.isWifi(context)) { httpResult.setStatus(HttpResult.STATUS_NOWIFI); httpResult.setErrorMsg("当前网络不是wifi"); return httpResult; } } try { Map<String, Object> returnResult = new HashMap<String, Object>(); String url = "http://mobilecdn.kugou.com/api/v3/rank/song"; Map<String, Object> params = new HashMap<String, Object>(); params.put("plat", "0"); params.put("version", "8352"); params.put("with_res_tag", "1"); params.put("ranktype", ranktype); params.put("rankid", rankid); params.put("page", page); params.put("pagesize", pagesize); // 获取数据 String result = HttpClientUtils.httpGetRequest(url, params); if (result != null) { result = result.substring(result.indexOf("{"), result.lastIndexOf("}") + 1); JSONObject jsonNode = new JSONObject(result); int status = jsonNode.getInt("status"); if (status == 1) { httpResult.setStatus(HttpResult.STATUS_SUCCESS); JSONObject dataJsonNode = jsonNode.getJSONObject("data"); returnResult.put("total", dataJsonNode.getInt("total")); JSONArray infoJsonNode = dataJsonNode.getJSONArray("info"); List<AudioInfo> lists = new ArrayList<AudioInfo>(); for (int i = 0; i < infoJsonNode.length(); i++) { JSONObject infoDataNode = infoJsonNode.getJSONObject(i); String fileName = infoDataNode.getString("filename"); String regex = "\\s*-\\s*"; String[] temps = fileName.split(regex); if (temps.length < 2) { continue; } //去掉首尾空格 String singerName = fileName.split(regex)[0].trim(); String songName = fileName.split(regex)[1].trim(); AudioInfo audioInfo = new AudioInfo(); audioInfo.setFileSize(infoDataNode.getLong("filesize")); audioInfo.setFileSizeText(MediaUtil.getFileSize(audioInfo.getFileSize())); audioInfo.setHash(infoDataNode.getString("hash").toLowerCase()); audioInfo.setSongName(songName); audioInfo.setSingerName(singerName.equals("")?"未知":singerName); audioInfo.setFileExt(infoDataNode.getString("extname")); audioInfo.setDuration(infoDataNode.getInt("duration") * 1000); audioInfo.setDurationText(MediaUtil.parseTimeToString((int) audioInfo.getDuration())); audioInfo.setType(AudioInfo.NET); audioInfo.setStatus(AudioInfo.INIT); SongInfoResult songInfoResult = SongInfoHttpUtil.songInfo(context, audioInfo.getHash()); if (songInfoResult != null) { audioInfo.setDownloadUrl(songInfoResult.getUrl()); // audioInfo.setAlbumUrl(songInfoResult.getImgUrl()); } lists.add(audioInfo); } returnResult.put("rows", lists); httpResult.setResult(returnResult); } else { httpResult.setStatus(HttpResult.STATUS_ERROR); httpResult.setErrorMsg("请求出错!"); } } } catch (Exception e) { e.printStackTrace(); httpResult.setStatus(HttpResult.STATUS_ERROR); httpResult.setErrorMsg(e.getMessage()); } return httpResult; }
购买套餐
权益 | 套餐A | 套餐B |
---|---|---|
完整代码 | ![]() |
![]() |
远程调试 | 不支持 | ![]() |
代码答疑 | 不支持 | ![]() |
价 格 | ¥260 | ¥420 |
------转载请注明出处,感谢您对原创作者的支持------
有偿提供技术支持、Bug修复、项目外包、毕业设计、大小作业
Android学习小站
Q Q:1095817610
微信:jx-helu
邮箱:1095817610@qq.com
添加请备注"Android学习小站"
