package com.android.music; import com.android.music.MusicUtils.ServiceToken; … public class MusicBrowserActivity extends Activity implements MusicUtils.Defs { /* * 在music的AndroidManifest.xml文件中,MusicBrowserActivity的intentfilter中定义了 * “<category android:name=”android.intent.category.LAUNCHER” />” * 表明MusicBrowserActivity是music启动时首先调用的activity */ private ServiceToken mToken; public MusicBrowserActivity() { } /** * Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); /* * getIntPref方法从名为com.android.music.xml的SharedPreferences文件中获取上一次退出时的状态 * 此文件中的内容如下: * <map> * <int name=”activetab” value=”2131361813″ /> * </map> */ int activeTab = MusicUtils.getIntPref(this, “activetab”, R.id.artisttab); if (activeTab != R.id.artisttab && activeTab != R.id.albumtab && activeTab != R.id.songtab && activeTab != R.id.playlisttab) { activeTab = R.id.artisttab; } //通过配置文件中保存的状态信息,调用activateTab方法跳转到对应的activity中去 MusicUtils.activateTab(this, activeTab); String shuf = getIntent().getStringExtra(“autoshuffle”); if (“true”.equals(shuf)) { mToken = MusicUtils.bindToService(this, autoshuffle); //bind到MusicPlaybackService类 } } @Override public void onDestroy() { if (mToken != null) { MusicUtils.unbindFromService(mToken); } super.onDestroy(); } private ServiceConnection autoshuffle = new ServiceConnection() { public void onServiceConnected(ComponentName classname, IBinder obj) { // we need to be able to bind again, so unbind try { unbindService(this); } catch (IllegalArgumentException e) { } //通过aidl接口,直接调用MusicPlaybackService中的setShuffleMode方法来设定播放模式为乱序播放 IMediaPlaybackService serv = IMediaPlaybackService.Stub.asInterface(obj); if (serv != null) { try { serv.setShuffleMode(MediaPlaybackService.SHUFFLE_AUTO); } catch (RemoteException ex) { } } } public void onServiceDisconnected(ComponentName classname) { } }; }
android自带musicplayer源码分析:MusicBrowserActivity类
原文作者:Android源码分析
原文地址: https://blog.csdn.net/monitor1379/article/details/6544559
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/monitor1379/article/details/6544559
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。