网友通过本文主要向大家介绍了安卓音乐播放器,安卓音乐播放器哪个好,安卓音乐播放器源码,安卓无损音乐播放器,安卓音乐播放器源代码等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
安卓第十七天笔记--简易版本音乐播放器,安卓第十七天
title:简易版本音乐播放器
简易版本音乐播放器
1.布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center_horizontal"> <Button android:id="@+id/musicList" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:background="#86B2F4" android:text="音乐文件列表" android:textColor="#fff" android:textSize="28sp"/> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/logo"/> <SeekBar android:id="@+id/seekBar" android:layout_width="match_parent" android:layout_height="wrap_content"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> <ImageButton android:id="@+id/stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/stop"/> <ImageButton android:id="@+id/pre" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pree"/> <ImageButton android:id="@+id/play" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/play"/> <ImageButton android:id="@+id/next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/next"/> </LinearLayout> </LinearLayout>
2.工具类
/** * Created by 刘楠 on 2016-03-05 19:39. * 文件过滤器工具类, * 用于过滤指定后缀的文件 */ public class MusicFileNameFilter implements FilenameFilter { private String type; public MusicFileNameFilter(String type) { this.type = type; } @Override public boolean accept(File dir, String filename) { return filename.endsWith(type); } }
3.Binder接口
/** * Created by 刘楠 on 2016-03-05 20:41. */ public interface IMusicPlayerService { public void callplay(String path); ; public void callStop(); public boolean callIsPlaying(); public int callGetgetDuration(); public int callGetgetCurrentDuration(); public boolean callMediaIsNull(); public void callChanageSeek(int position); public void callPause(); } 4. service /** * Created by 刘楠 on 2016-03-05 20:32. * * Servie音乐播放 */ public class MusicPlayerService extends Service { private MediaPlayer mediaPlayer; private MusicPlayerBinder musicPlayerBinder = new MusicPlayerBinder(); private class MusicPlayerBinder extends Binder implements IMusicPlayerService { public void callplay(String path) { play(path); } @Override public void callStop() { stop(); } @Override public boolean callIsPlaying() { return isPlaying(); } @Override public int callGetgetDuration() { return getgetDuration(); } @Override public int callGetgetCurrentDuration() { return getCurrentDuration(); } @Override public boolean callMediaIsNull() { return mediaIsNull(); } @Override public void callChanageSeek(int position) { chanageSeek(position); } @Override public void callPause() { pause(); } } @Nullable @Override public IBinder onBind(Intent intent) { return musicPlayerBinder; } /** * 初始化 * @param path */ private void init(String path) { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); reset(path); }else{ reset(path);