Monkey Music Player知识要点总结

要点概括
1、文件管理器,AlertDialog
2、Service应用,Notification通知栏,防止Service被杀,点击通知栏返回后台程序,(默认会创建新的Acticity)
3、Brodcast广播的应用
4、Activity之间的滑动切换
5、滑动侧边栏的实现,slideMenu类
6、响应实体按键,返回键使程序后台
7、程序被任务管理器强杀时的安全退出
8、Activity状态保存
9、歌词文件的解析与同步
10、在一个应用程序中启动另外一个已经安装的应用程序或系统程序
11、自定义PopupWindow菜单


(一)文件管理器

使用View界面布局生成对话框 AlertDialog dialog = new AlertDialog.Builder(this).setTitle("选择音乐目录").setView(viewDlg).create();
*****其中dialog不能多次调用setview(),否则会产生父视图已经包含子视图的异常。
View由含有ListView的layout布局文件生成 viewDlg = LayoutInflater.from(this).inflate(R.layout.filedialog, null);
ListView 设置条目点击监听器 listview.setOnItemClickListener
通过SimpleAdapter将List<Map<String,String>>关联到ListView.setAdapter();

(二)Service应用

在AndroidManifest.xml中注册Service
        <service
            android:name=".service.PlayerService"
            android:enabled="true"
            android:exported="true" >
        </service>
        
class PlayerService extends Service 需要继承Service,并重写onStartCommand()方法,调用startService(Intent);启动Service,进入onStartCommand()。

提高Service的生存能力

(1)在AndroidMainifest.xml文件中,主Activity中设置优先级

   <activity
            android:name=".PlayerActivity"
            android:label="@string/app_name">
            <intent-filter android:priority="1000">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
 (2)通过添加通知栏将Service设置成前台模式运行,使用 startForeground(0x111, notification);
 
 生成通知栏
  Notification notification = new Notification(R.drawable.notif_ico,
                getString(R.string.app_name), System.currentTimeMillis()); 第一个参数为通知栏图标,第二行为通知栏名字

        PendingIntent pendingintent = PendingIntent.getActivity(this, 0,
                new Intent(this, PlayerActivity.class), 0); PendingIntent是一种“待命Intent”,在需要的时候由使用者调用
                
        notification.setLatestEventInfo(this, FileUtil.getNameFromPath(mp3Path), "Monkey Music",
                pendingintent); 第一个参数为程序上下文,第二个参数为下拉栏里面第一行显示内容,第三个参数为下拉栏第二行的内容

 (3)设置Service标志START_STICKY,用于Service被强杀后的重启
 
 flags = START_STICKY;
 
 (4)如果设置了startForeground();必须在onDestory()中使用 stopForeground(true);进行退出处理。
 

 (三)Brodcast广播的应用
 
 1.继承BroadcastReceiver,并重写onReceive()方法。
 
 class LrcBroadcastReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {

            //获取当前歌词文本,更新UI
            String lrcMsg = intent.getStringExtra("lrcmsg");
            textView.setText(lrcMsg);
        }
 2.注册/解除广播
 
  注册前需要设置IntentFilter过滤动作,IntentFilter.addAction(String),其中String为自定义的动作
  registerReceiver(BroadcastReceiver, IntentFilter);
  unregisterReceiver(BroadcastReceiver);
 
  3.发送广播
  sendBroadcast(Intent);
 
 
 
(四)Activity之间的滑动切换
 

方法一: 

(1) 设置手势检测器GestureDetector,重写OnFling()方法.

         GestureDetector mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

                         @Override
                        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {   } 
                };
  (2)重写Activity的onTouchEvent方法,绑定GestureDetector处理触摸事件.
           @Override
         public boolean onTouchEvent(MotionEvent event) {
                              mGestureDetector.onTouchEvent(event);
                            return super.onTouchEvent(event);
             }


  方法二:

(1)Activity实现OnTouchListener和OnGestureListener接口,

  public class PlayerActivity extends Activity implements OnTouchListener,OnGestureListener {}
 
  (2)activity对应的layout绑定触摸和手势监听器
 
   mGestureDetector = new GestureDetector((OnGestureListener) this);
        LinearLayout viewSnsLayout = (LinearLayout)findViewById(R.id.playerLay);
        viewSnsLayout.setOnTouchListener(this);
        viewSnsLayout.setLongClickable(true);
 
  (3)并实现OnFling()方法,在onFling()方法中发送startActivity(Intent)启动其他Acticity
 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)方法
 
 
 (五)滑动侧边栏
 
 使用一个继承自ViewGroup的类SlidingMenu,使用其构造函数SlidingMenu(Context context, View main, View menu)
 将两个layout布局通过View view = LayoutInflater.from(this).inflate(R.layout.activity_main, null);合并成一个整体的View
 
在主Activity中的onCreate(Bundle savedInstanceState)中,使用setContentView(mSlidingMenu),将整合的mSliingMenu视图设置为主视图。

****menu视图中控件的查找可以使用listview = (ListView)menuView.findViewById(R.id.listview);

也可以调用SlidingMenu的mSlidingMenu.open()和close()方法打开和关闭侧边栏。

(六)响应实体按键,返回键使程序后台

重写Activity的onKeyDown(int keyCode, KeyEvent event)方法,
判断event = KeyEvent.KEYCODE_BACK时,使用 moveTaskToBack(false);使程序进入后台运行

(七)程序被任务管理器强杀时的安全退出

****一般程序必须添加在主Activity按返回键后台功能,否则会自动销毁程序,如果仍残留Service等其他服务,会造成无法正常清除Service,造成重启错误。
因为任务管理器在强杀时会调用现存主页Acticity的onDestory()方法,如果没有Activity存留,则无法在onDestory()中进行安全清除*******

重写onDestory()方法,在onDestory()方法中进行清除工作。

(八)Activity数据共享

(1)创建Java数据共享类,设置static成员变量和方法
当一个应用有多个Activity时,当某个Activity需要用到另外一个activity的数据时需要,可以使用Java数据共享类调用。

(九)歌词文件的解析与同步

使用广播机制同步发送歌词

(1)将歌词文件通过提取分成时间和对应的歌词内容,分别用两个队列保存。

Queue<Long> timeMills = new LinkedList<Long>();
Queue<String> messages = new LinkedList<String>();

 (2)内部类实现Runnable接口
 class UpdateTimeCallback implements Runnable{},实现run()方法
通过判断播放起始时间和当前时间的差值,查找时间队列,匹配后取出对应的歌词(注意暂停后的处理),使用sendBroadcast(Intent)发送

同时在run()方法中使用 handler.postDelayed(updateTimeCallback,10);第一个参数为Runnable实现类,第二个为多长时间后发送。

进行循环运行run()方法。实现同步歌词

需要停止循环时, 使用handler.removeCallbacks(updateTimeCallback);进行移除。



(十)在一个应用程序中启动另外一个已经安装的应用程序或系统程序

可以通过ComponentName以及Intent的setComponent来实现

//组件名称,第一个参数是应用程序的包名,后一个是这个应用程序的主Activity  
 ComponentName com = new ComponentName("com.antroid.Test", "com.antroid.Test.TestActivity");
 
 Intent  intent = new Intent();
 
 
 //设置部件     
 intent.setComponent(com);
 
 startActivity(intent);  

 (十一)自定义PopupWindow菜单
 
 菜单布局menu.xml
 通过布局转化视图View,通过View创建PopupWindow,并设置控件监听器
 通过InitWindow()设置好相关属性和dismiss()
 通过 popupWindow.showAtLocation(mainView, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL ,0,0);//根据mainview确定位置(在mainView当中)
     和popupWindow.showAsDropDown(mainView,0,0);//根据mainview确定位置(在mainview父窗口)
    
     最后通过判断isShowing()创建和关闭窗口。
    
    
     可以设置背景透明和打开窗口背景变暗
       //设置透明背景
        ColorDrawable cd = new ColorDrawable(0x000000);
        popupWindow.setBackgroundDrawable(cd);

         //产生背景变暗效果
             WindowManager.LayoutParams lp;
            lp=getWindow().getAttributes();
            lp.alpha = 0.4f;
            getWindow().setAttributes(lp);
            
            在dismiss中取消变暗
            
             public void onDismiss() {
                // TODO Auto-generated method stub
//                 WindowManager.LayoutParams lp=getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }


 
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
专业音频质量和独特的UI! Neutron具有自己的专业高清的32位音频渲染的核心,这有助于从你的Andr​​oid设备提供最佳音质外接扬声器或耳机。 Neutron具有复杂的UI,提供了先进的控制音乐播放。这是不容易的,这不是简单的POP音乐播放器,它适合发烧友和那些明白什么是音乐的人使用。推荐使用Hi-Fi/High-End音频硬件。 希望你会喜欢Neutron!有它的乐趣! 特点: * 32位音频解码/高品质HD音频处理。 *音频格式:MP1,MP2,MP3,OGG,FLAC(8,16,24,32位),WMA,AC3,AAC,M4A,M4B,M4R,MP4,3GP,3G2,MOV,APE, ALAC,西弗吉尼亚州(WavPack),MPC(MusePack),WAV(PCM {8,16,24,32 -位乐},ima4,MS - ADPCM,U -法律,法律),AU(PCM {8, 16,24,32,64位},U -法律,法),MPEG(音频),AVI(音频),iTunes的包容性,除了受DRM保护的。 *模块化的音频格式:按付款当日价格计算,IM的XM,S3M。 *语音音频格式:SPEEX。 * Ambiophonic R.A.C.E. DSP(外部扬声器的立体空间化)。 * Crossfeeding(立体声耳机缩小)。 *真正的无缝播放(音频采样准确)。 *交叉淡入淡出(包括手动跟踪,在播放切换)。 *抖动(音频信号量化避免)。 *实时重采样:速度快,质量,高保真音响。 *循环(播放列表,或跟踪)。 *重放增益(不支持的格式除外)。 * CUE文件的播放列表。 *总部4波段参数图形均衡器。 *实时频谱分析仪44 -波段。 *实时RMS栏。 *主/前置卷管理。 *横向和纵向的UI模式(包括反向)。 *简约部件:中子迷你。 *播放/空闲/唤醒状态的任务栏的通知。 *可移动的外置SD卡。 *播放排序:(源,专辑,艺术家,流派),洗牌(包括循环洗牌),循环的多个实例。 * Unicode的标签。 *独特的夜与动态音频可视化用户界面模式(屏幕闪烁)。 *滚动的专辑封面(支持格式:PNG,JPG)。 *取决于对音乐专辑封面抖动。 *时钟模式。 *睡眠定时器:15,30,45,60,90分钟。 *唤醒定时器。 *自动键锁(锁面积闪烁)与动态的色彩响应基础上,正在播放音乐。 *自定义设置。 推荐硬件: - 1GHz以上的CPU(单,或多核)。 - 480X800的屏幕分辨率,或更高。 激活说明: 先安装中子播放器,不要运行; 再安装激活器并激活,然后删除激活器;

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值