package com.autochips.music2; import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Timer; import java.util.TimerTask; import java.util.Vector; import android.app.Activity; import android.app.AlertDialog; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.content.AsyncQueryHandler; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.database.CharArrayBuffer; import android.database.Cursor; import android.database.StaleDataException; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.media.AudioManager; import android.media.audiofx.Visualizer; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.SystemProperties; import android.os.Parcel; import android.os.RemoteException; import android.os.SystemClock; import android.provider.MediaStore; import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.SeekBar; import android.widget.SimpleCursorAdapter; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import android.widget.Toast; import com.autochips.cbmctx.CBMCtx; import com.autochips.music2.R; import com.autochips.music2.RearManager.RearPresentation; import com.autochips.media.AtcMediaPlayer; import com.autochips.music2.MusicUtils.ServiceToken; import com.autochips.settings.AtcSettings; import com.autochips.storage.EnvironmentATC; import com.jbd.tool.FileList; import android.mcucom.McuComAddr; import android.mcucom.McuComKey; import android.mcucom.McuComSysState; import android.mcucom.McuComManager; public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,View.OnCreateContextMenuListener,ServiceConnection { private static final String LOGTAG = "[APP]MediaPlaybackActivity"; public static MediaPlaybackActivity activity = null; private Thread Scanner = null; public MyActivityManager mam; private EnvironmentATC environ; private String Amount = null; private String ScannerTag = null; private int DevicesFlag; private Cursor ListCursor = null; private static List<String> songfile=new ArrayList<String>(); private final static String KEY_PATH_INDEX = "audioindex"; private final static String KEY_INDEX = "subindex"; private final static String KEY_PLAY_TIME = "playtime"; public final static String KEY_PLAY_PATH = "playpath"; public final static String KEY_PATH_MEMORY_ID = "memoryId"; public final static String KEY_FOLDER_ID = "key_folder_id"; public final static String KEY_FOLDER_PATH = "key_folder_path"; private Boolean DEVICE = false; private String device_name = null; private Boolean DESTROY = false; private int mSelectedDelete; private String mounted_path = ""; public static String main_path = "123"; public static Boolean SUM = false; private static Boolean ENABLED = false; private SharedPreferences.Editor mEditor = null; private SharedPreferences mSharedPreference; private int basse = 0; private String[] eq = null; private int song_sum = 0; private int song_current = 0; private TextView mPlay_item; private String currentpath = ""; private Boolean sum = false; private String mainpath = ""; //add private Timer mPressedTimer; private TimerTask buttonTimertask; private Timer mTimer; private boolean Pressed = true; private boolean sd = true; private boolean DEVICESTAG = true; private ImageButton hide_list,equalizer; //-------------------------------------start private String[] mCursorCols; private ListView mTrackList; private FrameLayout equlizer; public static Cursor mTrackCursor; private TrackListAdapter mAdapter; private boolean mAdapterSent = false; private String mSortOrder; public final static int PLAYBACK_NONE_SPEED = 0; public final static int PLAYBACK_RATE_NORMAL = 1; public static int PLAYBACK_FF_RATE_MAX = 32; public static int PLAYBACK_RW_RATE_MAX = 32; public final static int CAP_FILE_SEEK_UNSUPPORT = 0x00000001; public final static int CAP_FILE_FF_UNSUPPORT = CAP_FILE_SEEK_UNSUPPORT << 1; public final static int CAP_FILE_RW_UNSUPPORT = CAP_FILE_FF_UNSUPPORT << 1; public static long SAVE_PROGRESS; // public static PlayStatus LAST_STATUS; public static int LAST_PLAYBACK_STATUS = -1; public static int mCurPlaybackRate = PLAYBACK_RATE_NORMAL; public enum PlayStatus { STATUS_NONE, STATUS_STOP, STATUS_PAUSE, STATUS_PLAY }; private boolean IS_UPDATE_FF_RW_BUTTON = true; private String mfilepath; private long mLastSeekEventTime; public static IMediaPlaybackService mService = null; private ImageButton mPrevButton; private ImageButton mNextButton; private Button mEqButton; private ImageButton mButtonMute; private ImageButton mButtonBRO; // private ImageView mTitleView; @InjectView(R.id.pause) public ImageView mPauseButton; @InjectView(R.id.repeat) public ImageButton mRepeatButton; @InjectView(R.id.index_indicator) public TextView mIndexIndicator; @InjectView(R.id.song_play_icon) public ImageView mIvTitlePlayIcon; @InjectView(R.id.song_ff_info) public TextView mIvTitleIconInfo; @InjectView(R.id.music_title) public TextView mPlayFileName; @InjectView(R.id.music_spectrum) private MusicSpectrumView mSpectrumView; @InjectView(R.id.music_lrc) public LrcView mLrcView; @InjectView(R.id.pagedview) public PagedView mPagedView; public Button mEqualizer; private Visualizer mVisualizer; // private Lyric mLyric; private Vector<LyricTimeContentInfo> lrc_map; // // private Worker mAlbumArtWorker; // private AlbumArtHandler mAlbumArtHandler; private Toast mToast; private ServiceToken mToken = null; private ServiceToken mToken1; private CBMCtx mCbmCtx; private RearManager mRearManager; public Fragment equlizerFragment; Class<?> mStatusBarManager; Method mMethod; Object mStatusbarService; private FragmentManager fragmentManager; private FragmentTransaction transaction; public static McuComManager gMCM = null; private static int g_sys_state = 0; public void send_command(int addr,byte[] data){ if (null != gMCM) gMCM.sendMcuComMultiData(addr,data); } public MediaPlaybackActivity() { } /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Log.d("my", "onCreate--------leave"); getWindow().setBackgroundDrawable(new ColorDrawable(0)); if (null == gMCM) gMCM = new McuComManager(); if (null != gMCM) { g_sys_state = gMCM.getSystemState(); if(g_sys_state!=McuComSysState.CAR_MPEG_SYS_POWEROFF) { if(g_sys_state != McuComSysState.CAR_MPEG_SYS_SD) { g_sys_state = McuComSysState.CAR_MPEG_SYS_SD; gMCM.setSystemState(g_sys_state); byte[] data = McuComKey.getKeyData( McuComKey.CAR_KEY_ATTR_TOUCH, McuComKey.SHORTKEY, McuComKey.CAR_KEY_SD_SEL); send_command(McuComAddr.CAR_MPEG_KEY_ADR, data); } gMCM.setMcuComClient(); gMCM.setOnActionListener(mAudioAction); basse = gMCM.getEQMode(); sendBroadcast(new Intent("com.android.jbd.equsermode")); int a = gMCM.getSysScanDevFlag(); Log.i("my", a+""); if((a & 0x0001) == 0x0001) device_name = "/mnt/ext_sd"; if((a & 0x0004) == 0x0004) device_name = "/mnt/udisk1"; if((a & 0x0008) == 0x0008) device_name = "/mnt/udisk2"; if((a & 0x0010) == 0x0010) device_name = "/mnt/udisk3"; if((a & 0x0020) == 0x0020) device_name = "/mnt/udisk4"; if((a & 0x0040) == 0x0040) device_name = "/mnt/udisk5"; // if((a & 0x0080) == 0x0080) device_name = "/mnt/udisk6"; // if((a & 0x0100) == 0x0100) device_name = "/mnt/udisk7"; // if((a & 0x0200) == 0x0200) device_name = "/mnt/udisk8"; // if((a & 0x0400) == 0x0400) device_name = "/mnt/udisk9"; // if((a & 0x0400) == 0x0400) device_name = "/mnt/udisk10"; } } //------------------------------------------start setVolumeControlStream(AudioManager.STREAM_MUSIC); mCursorCols = new String[] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ARTIST_ID,MediaStore.Audio.Media.SIZE, MediaStore.Audio.Media.DURATION }; setVolumeControlStream(AudioManager.STREAM_MUSIC); mStatusbarService = getSystemService("statusbar"); mRearManager = new RearManager(this); //kaicer move listener down 20151216 // mAlbumArtWorker = new Worker("album art worker"); // mAlbumArtHandler = new AlbumArtHandler(mAlbumArtWorker.getLooper()); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.music_player); activity = this; mam = MyActivityManager.getInstance(); mam.pushOneActivity(MediaPlaybackActivity.this); environ = new EnvironmentATC(this); mSharedPreference = MediaPlaybackActivity.this.getSharedPreferences("com.android.settings_preferences", Context.MODE_PRIVATE); mEditor = mSharedPreference.edit(); // int FolderId = mSharedPreference.getInt(KEY_FOLDER_ID, -1); // if(DevicesFlag != 0) ((MusicApplication) getApplication()).setFolderID(-1); // else ((MusicApplication) getApplication()).setFolderID(FolderId); if(device_name != null) { mounted_path = device_name; mEditor.putString(KEY_PATH_INDEX,device_name); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); }; eq = getResources().getStringArray(R.array.eq_sound); /* fragmentManager = getFragmentManager(); transaction = fragmentManager.beginTransaction(); equlizerFragment = new EqulizerFragment(); transaction.replace(R.id.equlizer_la, equlizerFragment, "EQ_FRG"); transaction.commit(); */ mTrackList = (ListView)this.findViewById(R.id.song_list); equlizer = (FrameLayout)this.findViewById(R.id.equlizer_la); mTrackList.setOnItemClickListener(Listener); mTrackList.setSelector(R.drawable.adapter_background); // mAdapter = new TrackListAdapter(getApplication(), this, // R.layout.track_list_item, null, new String[] {}, // new int[] {}, false, false); mAdapter = new TrackListAdapter(MediaPlaybackActivity.this,getApplication(),songfile); if (mAdapter != null) { mTrackList.setAdapter(mAdapter); } hide_list = (ImageButton) findViewById(R.id.hide_list); equalizer = (ImageButton) findViewById(R.id.equalizer); hide_list.setOnClickListener(list_Listener); equalizer.setOnClickListener(list_Listener); mPlay_item = (TextView) findViewById(R.id.play_item); mCurrentTime = (TextView) findViewById(R.id.currenttime); mTotalTime = (TextView) findViewById(R.id.totaltime); mProgress = (ProgressBar) findViewById(android.R.id.progress); mArtistName = (TextView) findViewById(R.id.artistname); mAlbumName = (TextView) findViewById(R.id.albumname); mIvTitlePlayIcon = (ImageView) findViewById(R.id.song_play_icon); mIvTitleIconInfo = (TextView) findViewById(R.id.song_ff_info); mPagedView = (PagedView) findViewById(R.id.pagedview); mButtonMute = (ImageButton) findViewById(R.id.music_mute); mButtonMute.setOnClickListener(mMuteListener); mButtonMute.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View arg0) { byte[] power = McuComKey.getKeyData( McuComKey.CAR_KEY_ATTR_TOUCH, McuComKey.SHORTKEY, McuComKey.CAR_KEY_TFT_SCR_POWER); send_command(McuComAddr.CAR_MPEG_KEY_ADR, power); return true; } }); mButtonBRO = (ImageButton) findViewById(R.id.music_browse); mButtonBRO.setOnClickListener(mbrowseListener); mPlayFileName = (TextView) findViewById(R.id.music_title); //mPlayFileName.setText(mfilepath); mLrcView = (LrcView) findViewById(R.id.music_lrc);// mEqButton = (Button) findViewById(R.id.music_eq); mEqButton.setTextSize(20); mEqButton.setOnClickListener(mEqListener); mSpectrumView = (MusicSpectrumView) findViewById(R.id.music_spectrum); mSpectrumView.create(20, 50, 1, 15,3);//20, 50, 1, 10,2 mRepeatButton = (ImageButton) findViewById(R.id.repeat); mRepeatButton.setOnClickListener(mRepeatListener); mPrevButton = (ImageButton) findViewById(R.id.prev); mPrevButton.setOnClickListener(mPrevListener); mPauseButton = (ImageView) findViewById(R.id.pause); mPauseButton.requestFocus(); mPauseButton.setOnClickListener(mPauseListener); mNextButton = (ImageButton) findViewById(R.id.next); mNextButton.setOnClickListener(mNextListener); if (mProgress instanceof SeekBar) { SeekBar seeker = (SeekBar) mProgress; seeker.setOnSeekBarChangeListener(mSeekListener); } mProgress.setMax(1000); //kaicer move here 20151216 IntentFilter f = new IntentFilter(); f.addAction(MediaPlaybackService.ACTION_CBM_CHANGE); registerReceiver(mCbmListener, new IntentFilter(f)); f = new IntentFilter(); f.addAction(MediaPlaybackService.ACTION_QB_POWERON); f.addAction(MediaPlaybackService.ACTION_QB_POWEROFF); f.addAction(MediaPlaybackService.ACTION_QB_POWERON_COMPLETE); f.addAction("android.delete.item"); f.addAction("ACTION.COLSE.MUSIC"); registerReceiver(mQuickBootListener, new IntentFilter(f)); f = new IntentFilter(); f.addAction(MediaPlaybackService.PLAYSTATE_CHANGED); f.addAction(MediaPlaybackService.META_CHANGED); f.addAction(MediaPlaybackService.FORCESTOPACTIVITY); f.addAction(MediaPlaybackService.FINISHACTIVITY); f.addAction(MediaPlaybackService.OPEN_REAR); registerReceiver(mStatusListener, new IntentFilter(f)); f = new IntentFilter(); f.addAction(MediaPlaybackService.START_PLAY); registerReceiver(mStartPlay, new IntentFilter(f)); IntentFilter f1 = new IntentFilter(); f1.addAction(MediaPlaybackService.START_PLAY); registerReceiver(mStartPlayListener, new IntentFilter(f1)); //kaicer move here 20151216 mToken = MusicUtils.bindToService(this, osc); if (mToken == null) { // something went wrong mHandler.sendEmptyMessage(QUIT); } getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); try { MusicUtils.displayDatabaseError(MediaPlaybackActivity.this); mToken1 = MusicUtils.bindToService(this, this); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //play_song.sendEmptyMessageDelayed(0,3000); //basse = mSharedPreference.getInt("BASSE", 0); //((MusicApplication) getApplication()).setEQMode(basse); //setEQDry(basse); mEqButton.setText(eq[basse]); } @Override protected void onRestart() { Log.i("my", "onRestart"); try { if (mService != null) { if (mService.isPlaying()) { //..... } else { if (mCurPlaybackRate != PLAYBACK_RATE_NORMAL) { mCurPlaybackRate = setPlaybackRate(PLAYBACK_RATE_NORMAL); } if (mService.duration() == -1) { mService.rePlay(); LAST_PLAYBACK_STATUS = AtcMediaPlayer.MEDIA_PLAYER_STARTED; if (mVisualizer == null) { link(mService.getAudioSessionId()); } mHandler.sendEmptyMessage(REFRESH); } else { mService.play(); LAST_PLAYBACK_STATUS = AtcMediaPlayer.MEDIA_PLAYER_STARTED; refreshNow(); } updateTitleIconPlayState(PlayStatus.STATUS_PLAY); mProgress.setEnabled(true); } setPauseButtonImage(); } } catch (RemoteException ex) { } super.onRestart(); } private int initCheckSD(){ String[] strState = environ.getSdMountedPaths(); if(strState.length > 0) { // if(Arrays.asList(strState).contains("/mnt/ext_sdcard1")) // return 1; for(int i = 0;i<strState.length;i++) { if(strState[i].contains("/mnt/ext_sdcard2")) return 1; } } return 0; } private int initCheckUSB(){ String[] strState = environ.getUsbMountedPaths(); if(strState.length > 0) { // if(Arrays.asList(strState).contains("/mnt/udisk1")) // return 1; for(int i = 0;i<strState.length;i++) { if(strState[i].contains("/mnt/udisk1")) return 1; } } return 0; } //add usb2 private int initCheckUSB2(){ String[] strState = environ.getUsbMountedPaths(); if(strState.length > 0) { // if(Arrays.asList(strState).contains("/mnt/udisk2")) // return 1; for(int i = 0;i<strState.length;i++) { if(strState[i].contains("/mnt/udisk2")) return 1; } } return 0; } //add usb3 private int initCheckUSB3(){ String[] strState = environ.getUsbMountedPaths(); if(strState.length > 0) { // if(Arrays.asList(strState).contains("/mnt/udisk3")) // return 1; for(int i = 0;i<strState.length;i++) { if(strState[i].contains("/mnt/udisk3")) return 1; } } return 0; } //add usb4 private int initCheckUSB4(){ String[] strState = environ.getUsbMountedPaths(); if(strState.length > 0) { // if(Arrays.asList(strState).contains("/mnt/udisk4")) // return 1; for(int i = 0;i<strState.length;i++) { if(strState[i].contains("/mnt/udisk4")) return 1; } } return 0; } //add usb5 private int initCheckUSB5(){ String[] strState = environ.getUsbMountedPaths(); if(strState.length > 0) { // if(Arrays.asList(strState).contains("/mnt/udisk5")) // return 1; for(int i = 0;i<strState.length;i++) { if(strState[i].contains("/mnt/udisk5")) return 1; } } return 0; } private McuComManager.OnActionListener mAudioAction= new McuComManager.OnActionListener() { public int onAction(int adr, int data) { switch(adr) { case McuComManager.SYS_UPDATE_KEY: mMcuHandler.sendEmptyMessage(data); break; } return 0; } }; private Handler mMcuHandler = new Handler() { @Override public void handleMessage(Message msg) { switch(msg.what) { case McuComKey.CAR_KEY_MENU_EXIT: /* if(gMCM!=null) g_sys_state = gMCM.getSystemState(); if(g_sys_state==McuComSysState.CAR_MPEG_SYS_POWEROFF) { try { if (mService != null) { if (mService.isPlaying()) { mService.pause(); } } } catch (RemoteException ex) { } } else */ { DESTROY = true; Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); SaveState(); finish(); Log.i("my", "finish()-----------------------------------"); //System.exit(0); } break; case McuComKey.CAR_KEY_PLAYPAUSE: onPlaypauseButton(); break; case McuComKey.CAR_KEY_PREV: onPrevButton(); break; case McuComKey.CAR_KEY_NEXT: onNextButton(); break; case McuComKey.CAR_KEY_FB: //onFBButton(); break; case McuComKey.CAR_KEY_FF: //onFFButton(); break; case McuComKey.CAR_KEY_STOP: onStopButton(); break; case McuComKey.CAR_KEY_REPEAT: onRepeatButton(); break; } } }; //--------------------------statart private BroadcastReceiver mStartPlayListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } } }; public void onServiceConnected(ComponentName name, IBinder service) { IntentFilter f = new IntentFilter(); f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); f.addAction(Intent.ACTION_MEDIA_UNMOUNTED); f.addAction(Intent.ACTION_MEDIA_REMOVED);//add f.addAction(Intent.ACTION_MEDIA_EJECT); f.addAction(Intent.ACTION_MEDIA_MOUNTED); f.addDataScheme("file"); registerReceiver(mScanListener, f); songfile.clear(); Scanner = new Thread(checkSd); Scanner.start(); if (mAdapter == null) { // mAdapter = new TrackListAdapter(getApplication(), this, // R.layout.track_list_item, null, new String[] {}, // new int[] {}, false, false); mAdapter = new TrackListAdapter(MediaPlaybackActivity.this,getApplication(),songfile); //setListAdapter(mAdapter); mTrackList.setAdapter(mAdapter); //setTitle(R.string.working_songs); if(initCheckSD() == 0 && initCheckUSB() == 0 && initCheckUSB2() == 0 && initCheckUSB3() == 0 && initCheckUSB4() == 0 && initCheckUSB5() == 0) getTrackCursor( null, true); else { String folder = mSharedPreference.getString(KEY_FOLDER_PATH, ""); ((MusicApplication) getApplication()).set_Play(folder); File fl=new File(folder); if(fl.isDirectory() && FileList.FileType(folder)) { getTrackCursor1( null, true,"'%"+folder+"%'"); // folder memory }else{ String path = mSharedPreference.getString(KEY_PATH_INDEX, ""); if(path.equals("/mnt/ext_sd") && initCheckSD() == 1) getTrackCursor1( null, true,"'%/mnt/ext_sdcard2/%'"); else if(path.equals("/mnt/udisk1") && initCheckUSB() == 1) getTrackCursor1( null, true,"'%/mnt/udisk1/%'"); else if(path.equals("/mnt/udisk2") && initCheckUSB2() == 1) //add usb2 getTrackCursor1( null, true,"'%/mnt/udisk2/%'");//add usb2 else if(path.equals("/mnt/udisk3") && initCheckUSB3() == 1) //add usb3 getTrackCursor1( null, true,"'%/mnt/udisk3/%'");//add usb3 else if(path.equals("/mnt/udisk4") && initCheckUSB4() == 1) //add usb4 getTrackCursor1( null, true,"'%/mnt/udisk4/%'");//add usb4 else if(path.equals("/mnt/udisk5") && initCheckUSB5() == 1) //add usb5 getTrackCursor1( null, true,"'%/mnt/udisk5/%'");//add usb5 else { if(initCheckSD() == 1) getTrackCursor1( null, true,"'%/mnt/ext_sdcard2/%'"); else if(initCheckUSB() == 1) getTrackCursor1( null, true,"'%/mnt/udisk1/%'"); else if(initCheckUSB2() == 1) //add usb2 getTrackCursor1( null, true,"'%/mnt/udisk2/%'");//add usb2 else if(initCheckUSB3() == 1) //add usb3 getTrackCursor1( null, true,"'%/mnt/udisk3/%'");//add usb3 else if(initCheckUSB4() == 1) //add usb4 getTrackCursor1( null, true,"'%/mnt/udisk4/%'");//add usb4 else if(initCheckUSB5() == 1) //add usb5 getTrackCursor1( null, true,"'%/mnt/udisk5/%'");//add usb5 mEditor.putString(KEY_PATH_INDEX,""); mEditor.commit(); } } } } else { // if (mTrackCursor != null) { // init(mTrackCursor, false); // } else { //setTitle(R.string.working_songs); Log.i("my", "--------------------------------->>>>>4"); if(initCheckSD() == 1 || initCheckUSB() == 1 || initCheckUSB2() == 1 || initCheckUSB3() == 1 || initCheckUSB4() == 1 || initCheckUSB5() == 1) // getTrackCursor( null, true); // else { String folder = mSharedPreference.getString(KEY_FOLDER_PATH, ""); ((MusicApplication) getApplication()).set_Play(folder); File fl=new File(folder); if(fl.isDirectory() && FileList.FileType(folder)) { getTrackCursor1( null, true,"'%"+folder+"%'"); // folder memory }else{ String path = mSharedPreference.getString(KEY_PATH_INDEX, ""); if(path.equals("/mnt/ext_sd") && initCheckSD() == 1) getTrackCursor1( null, true,"'%/mnt/ext_sdcard2/%'"); else if(path.equals("/mnt/udisk1") && initCheckUSB() == 1) getTrackCursor1( null, true,"'%/mnt/udisk1/%'"); else if(path.equals("/mnt/udisk2") && initCheckUSB2() == 1) //add usb2 getTrackCursor1( null, true,"'%/mnt/udisk2/%'");//add usb2 else if(path.equals("/mnt/udisk3") && initCheckUSB3() == 1) //add usb3 getTrackCursor1( null, true,"'%/mnt/udisk3/%'");//add usb3 else if(path.equals("/mnt/udisk4") && initCheckUSB4() == 1) //add usb4 getTrackCursor1( null, true,"'%/mnt/udisk4/%'");//add usb4 else if(path.equals("/mnt/udisk5") && initCheckUSB5() == 1) //add usb5 getTrackCursor1( null, true,"'%/mnt/udisk5/%'");//add usb5 else { if(initCheckSD() == 1) getTrackCursor1( null, true,"'%/mnt/ext_sdcard2/%'"); else if(initCheckUSB() == 1) getTrackCursor1( null, true,"'%/mnt/udisk1/%'"); else if(initCheckUSB2() == 1) //add usb2 getTrackCursor1( null, true,"'%/mnt/udisk2/%'");//add usb2 else if(initCheckUSB3() == 1) //add usb3 getTrackCursor1( null, true,"'%/mnt/udisk3/%'");//add usb3 else if(initCheckUSB4() == 1) //add usb4 getTrackCursor1( null, true,"'%/mnt/udisk4/%'");//add usb4 else if(initCheckUSB5() == 1) //add usb5 getTrackCursor1( null, true,"'%/mnt/udisk5/%'");//add usb5 mEditor.putString(KEY_PATH_INDEX,""); mEditor.commit(); } } } // } } // mTimer = new Timer(); // TimerTask buttonTimertask1 = new TimerTask() { // public void run() { // if(mTrackCursor.getCount() < 1 && mTrackCursor != null && // initCheckUSB() == 1 && device_name == null) // getTrackCursor1( null, true,"'%/mnt/udisk1/%'"); // else if(initCheckUSB4() == 1) getTrackCursor1( null, true,"'%/mnt/udisk4/%'"); // if(mTimer != null){ // mTimer.cancel(); // mTimer = null; // } // } // }; // mTimer.schedule(buttonTimertask1,1000); } public void onServiceDisconnected(ComponentName name) { finish(); } @Override public Object onRetainNonConfigurationInstance() { TrackListAdapter a = mAdapter; mAdapterSent = true; return a; } private void unregisterReceiverSafe(BroadcastReceiver receiver) { try { unregisterReceiver(receiver); } catch (IllegalArgumentException e) { // ignore } } private void updateTrackList() { if (mTrackCursor != null) { mTrackList.invalidateViews(); } } private BroadcastReceiver mScanListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (Intent.ACTION_MEDIA_SCANNER_STARTED.equals(action) || Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action)) { MusicUtils.setSpinnerState(MediaPlaybackActivity.this); } if (Intent.ACTION_MEDIA_EJECT.equals(action) || Intent.ACTION_MEDIA_REMOVED.equals(action)) { //TrackListAdapter.Trackremove(); sd = false; try { if(mTrackCursor != null ) { if(mTrackCursor.getCount() >= mService.getQueuePosition()) { mTrackCursor.moveToPosition(mService.getQueuePosition()); String url = mTrackCursor.getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); String sss = url.subSequence(0, 11).toString(); String path = intent.getData().toString().substring("file://".length()); startUpGrade(path,sss); } }else{ ((MusicApplication) getApplication()).setFolderID(-1); mEditor.putInt(KEY_FOLDER_ID,-1); mEditor.commit(); DESTROY = true; DEVICESTAG = false; mEditor.putString(KEY_PLAY_PATH,""); mEditor.putString(KEY_PATH_INDEX, ""); mEditor.putLong(KEY_PLAY_TIME,0); mEditor.putLong(KEY_PATH_MEMORY_ID, 0); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); onStopButton(); Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); finish(); } } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } //MusicUtils.displayDatabaseError(MediaPlaybackActivity.this); //finish(); } if (Intent.ACTION_MEDIA_MOUNTED.equals(action)) { // MusicUtils.displayDatabaseError(MediaPlaybackActivity.this); //Thread Sd = new Thread(checkSd); //Sd.start(); mounted_path = intent.getData().toString() .substring("file://".length()); // startUpdate(mounted_path); Message msg = new Message(); Bundle data = new Bundle(); data.putString("DEVICES", mounted_path); msg.what = 1; msg.setData(data); DevicesHandler.sendMessageDelayed(msg, 2000); } // mReScanHandler.sendEmptyMessage(0); } }; public void startUpGrade(String path,String state) { if(path.equals("/mnt/ext_sdcard2") && state.equals("/mnt/ext_sd")) { ((MusicApplication) getApplication()).setFolderID(-1); mEditor.putInt(KEY_FOLDER_ID,-1); mEditor.commit(); DESTROY = true; DEVICESTAG = false; mEditor.putString(KEY_PLAY_PATH,""); mEditor.putString(KEY_PATH_INDEX, ""); mEditor.putLong(KEY_PLAY_TIME,0); mEditor.putLong(KEY_PATH_MEMORY_ID, 0); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); // Uri uri = MyUsers.User.CONTENT_URI; // ContentResolver resolver = MediaPlaybackActivity.this.getContentResolver(); // resolver.delete(uri, MediaStore.Audio.Media.DATA + " LIKE ?", new String[]{"%/mnt/ext_sdcard1/%"}); onStopButton(); Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); finish(); } if(path.equals("/mnt/udisk1") && state.equals("/mnt/udisk1")) { ((MusicApplication) getApplication()).setFolderID(-1); mEditor.putInt(KEY_FOLDER_ID,-1); mEditor.commit(); DESTROY = true; DEVICESTAG = false; mEditor.putString(KEY_PLAY_PATH,""); mEditor.putString(KEY_PATH_INDEX, ""); mEditor.putLong(KEY_PLAY_TIME,0); mEditor.putLong(KEY_PATH_MEMORY_ID, 0); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); // Uri uri = MyUsers.User.CONTENT_URI; // ContentResolver resolver = MediaPlaybackActivity.this.getContentResolver(); // resolver.delete(uri, MediaStore.Audio.Media.DATA + " LIKE ?", new String[]{"%/mnt/udisk1/%"}); onStopButton(); Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); finish(); } //add usb2 if(path.equals("/mnt/udisk2") && state.equals("/mnt/udisk2")) { ((MusicApplication) getApplication()).setFolderID(-1); mEditor.putInt(KEY_FOLDER_ID,-1); mEditor.commit(); DESTROY = true; DEVICESTAG = false; mEditor.putString(KEY_PLAY_PATH,""); mEditor.putString(KEY_PATH_INDEX, ""); mEditor.putLong(KEY_PLAY_TIME,0); mEditor.putLong(KEY_PATH_MEMORY_ID, 0); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); // Uri uri = MyUsers.User.CONTENT_URI; // ContentResolver resolver = MediaPlaybackActivity.this.getContentResolver(); // resolver.delete(uri, MediaStore.Audio.Media.DATA + " LIKE ?", new String[]{"%/mnt/udisk2/%"}); onStopButton(); Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); finish(); } //add usb2 end //add usb3 if(path.equals("/mnt/udisk3") && state.equals("/mnt/udisk3")) { ((MusicApplication) getApplication()).setFolderID(-1); mEditor.putInt(KEY_FOLDER_ID,-1); mEditor.commit(); DESTROY = true; DEVICESTAG = false; mEditor.putString(KEY_PLAY_PATH,""); mEditor.putString(KEY_PATH_INDEX, ""); mEditor.putLong(KEY_PLAY_TIME,0); mEditor.putLong(KEY_PATH_MEMORY_ID, 0); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); // Uri uri = MyUsers.User.CONTENT_URI; // ContentResolver resolver = MediaPlaybackActivity.this.getContentResolver(); // resolver.delete(uri, MediaStore.Audio.Media.DATA + " LIKE ?", new String[]{"%/mnt/udisk3/%"}); onStopButton(); Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); finish(); } //add usb3 end //add usb4 if(path.equals("/mnt/udisk4") && state.equals("/mnt/udisk4")) { ((MusicApplication) getApplication()).setFolderID(-1); mEditor.putInt(KEY_FOLDER_ID,-1); mEditor.commit(); DESTROY = true; DEVICESTAG = false; mEditor.putString(KEY_PLAY_PATH,""); mEditor.putString(KEY_PATH_INDEX, ""); mEditor.putLong(KEY_PLAY_TIME,0); mEditor.putLong(KEY_PATH_MEMORY_ID, 0); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); // Uri uri = MyUsers.User.CONTENT_URI; // ContentResolver resolver = MediaPlaybackActivity.this.getContentResolver(); // resolver.delete(uri, MediaStore.Audio.Media.DATA + " LIKE ?", new String[]{"%/mnt/udisk4/%"}); onStopButton(); Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); finish(); } //add usb4 end //add usb5 if(path.equals("/mnt/udisk5") && state.equals("/mnt/udisk5")) { ((MusicApplication) getApplication()).setFolderID(-1); mEditor.putInt(KEY_FOLDER_ID,-1); mEditor.commit(); DESTROY = true; DEVICESTAG = false; mEditor.putString(KEY_PLAY_PATH,""); mEditor.putString(KEY_PATH_INDEX, ""); mEditor.putLong(KEY_PLAY_TIME,0); mEditor.putLong(KEY_PATH_MEMORY_ID, 0); mEditor.putString(KEY_FOLDER_PATH,""); mEditor.commit(); // Uri uri = MyUsers.User.CONTENT_URI; // ContentResolver resolver = MediaPlaybackActivity.this.getContentResolver(); // resolver.delete(uri, MediaStore.Audio.Media.DATA + " LIKE ?", new String[]{"%/mnt/udisk5/%"}); onStopButton(); Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 1); sendBroadcast(intent2); finish(); } //add usb5 end } public void startUpdate(String path) { if(path.contains("/mnt/ext_sdcard2")) { ((MusicApplication) getApplication()).setFolderID(-1); mTrackCursor.close(); mTrackCursor = null; getTrackCursor1(null, true,"'%/mnt/ext_sdcard2/%'"); onStopButton(); DEVICE = true; } if(path.contains("/mnt/udisk1")) { ((MusicApplication) getApplication()).setFolderID(-1); mTrackCursor.close(); mTrackCursor = null; getTrackCursor1(null, true,"'%/mnt/udisk1/%'"); onStopButton(); DEVICE = true; } //add usb2 if(path.contains("/mnt/udisk2")) { ((MusicApplication) getApplication()).setFolderID(-1); mTrackCursor.close(); mTrackCursor = null; getTrackCursor1( null, true,"'%/mnt/udisk2/%'"); onStopButton(); DEVICE = true; } //add usb2 end //add usb3 if(path.contains("/mnt/udisk3")) { ((MusicApplication) getApplication()).setFolderID(-1); mTrackCursor.close(); mTrackCursor = null; getTrackCursor1( null, true,"'%/mnt/udisk3/%'"); onStopButton(); DEVICE = true; } //add usb3 end //add usb4 if(path.contains("/mnt/udisk4")) { Log.i("my", "========/mnt/udisk4"); ((MusicApplication) getApplication()).setFolderID(-1); mTrackCursor.close(); mTrackCursor = null; getTrackCursor1( null, true,"'%/mnt/udisk4/%'"); onStopButton(); DEVICE = true; } //add usb4 end //add usb5 if(path.contains("/mnt/udisk5")) { ((MusicApplication) getApplication()).setFolderID(-1); mTrackCursor.close(); mTrackCursor = null; getTrackCursor1( null, true,"'%/mnt/udisk5/%'"); onStopButton(); DEVICE = true; Log.i("my", "/mnt/udisk5"); } //add usb5 end } //zhou add 2015/12/28 Handler DevicesHandler = new Handler() { public void handleMessage(android.os.Message msg) { Bundle bundle = msg.getData(); String data = bundle.getString("DEVICES"); startUpdate(data); } }; Runnable checkSd = new Runnable() { public void run() { MuteHandler.sendEmptyMessage(1); if(songfile != null && songfile.size() > 0) { play_song.sendEmptyMessage(0); // play_song.postDelayed(checkSd, 500); } play_song.postDelayed(checkSd, 500); } }; //zhou add mute 2015/12/23 Handler MuteHandler = new Handler() { public void handleMessage(android.os.Message msg) { music_bMute = isMuted(AudioManager.STREAM_MUSIC); if(mButtonMute != null) { if(music_bMute == true) mButtonMute.setBackgroundResource(R.drawable.button_mute); else mButtonMute.setBackgroundResource(R.drawable.button_voice); } } }; //zhou add mute 2015/12/23 private static final int STREAM_MASTER = -100; private AudioManager aManager = null; private Boolean music_bMute; private boolean isMuted(int streamType) { if (aManager == null) { aManager = (AudioManager) MediaPlaybackActivity.this.getSystemService(Context.AUDIO_SERVICE); } if (streamType == STREAM_MASTER) { return aManager.isMasterMute(); }else { return aManager.isStreamMute(streamType); } } public boolean isShowRearButton() { String rearproperty = SystemProperties.get("atc.rearproperty", BaseRearManager.REAR_PROPERTY_NULL); return !BaseRearManager.REAR_PROPERTY_NULL .equalsIgnoreCase(rearproperty); } public void onRearButtonClick() { if (mRearManager.getRearPresentation() == null) { mRearManager.openRear(); openRearAudio(); BaseRearManager.IS_REAR_OPENING = true; } else { mRearManager.closeRear(); closeRearAudio(); BaseRearManager.IS_REAR_OPENING = false; } } private void refreshRearView(View v,Message msg) { RearPresentation rp = mRearManager.getRearPresentation(); if (rp != null && v != null) { View rearView = rp.findViewById(v.getId()); rearView.setVisibility(v.getVisibility()); if (v instanceof PagedView) { PagedView pagedView = (PagedView)rearView; int curPage = ((PagedView)v) .getCurrentPage(); pagedView.quickSnapToPage(curPage); } } } private void refreshRearView(View v) { RearPresentation rp = mRearManager.getRearPresentation(); if (rp != null && v != null) { View rearView = rp.findViewById(v.getId()); rearView.setVisibility(v.getVisibility()); if (v instanceof TextView) { v.setTag(((TextView) v).getText()); ((TextView) rearView).setText(((TextView) v).getText()); return; } if (v instanceof ProgressBar) { v.setTag(((ProgressBar) v).getProgress()); ((ProgressBar) rearView).setProgress(((ProgressBar) v) .getProgress()); return; } if (v instanceof ImageButton) { ((ImageButton) rearView).setBackgroundResource((Integer) v .getTag()); return; } if (v instanceof ImageView) { Object tag = v.getTag(); if (tag != null) { if (tag instanceof Bitmap) { ((ImageView) rearView).setImageBitmap((Bitmap) tag); } else { ((ImageView) rearView).setImageResource((Integer) tag); } } return; } if (v instanceof MusicSpectrumView) { ((MusicSpectrumView) rearView).display((byte[]) v.getTag()); return; } if (v instanceof LrcView) { TextView[] childs = ((LrcView) v).getChildViews(); TextView[] rearChilds = ((LrcView) rearView).getChildViews(); for (int i = 0; i < childs.length; i++) { rearChilds[i].setText(childs[i].getText()); rearChilds[i].setVisibility(childs[i].getVisibility()); rearChilds[i].setTextColor(childs[i].getTextColors()); } } } } //play_song Handler play_song = new Handler() { public void handleMessage(android.os.Message msg) { try { //Log.i("my", mTrackCursor+"-----------------================="+MusicUtils.FLAG); if(mService == null || mTrackCursor == null || !MusicUtils.FLAG) { handler.sendEmptyMessageDelayed(100, 1000); return; } //Log.i("my", "+++++++++++++++++++++++++++++++++++++"); if(mService.isPlaying()) { sd = false; ENABLED = true; } //Log.i("my", mService.isPlaying()+":mService.isPlaying()"+sd+":sd"+mTrackCursor.getCount()+":mTrackCursor.getCount()"); if(!mService.isPlaying() && sd && mTrackCursor.getCount() != 0) { String path = mSharedPreference.getString(KEY_PATH_INDEX, ""); if(path.equals("")) MusicUtils.playAll(MediaPlaybackActivity.this, mTrackCursor, 0); else handler.sendEmptyMessageDelayed(1, 0); //MusicUtils.playAll(MediaPlaybackActivity.this, mTrackCursor, 0); Log.i("my", "*******************ok*******************"); } // update music_list; if(mService.getPlayListLen() != mTrackCursor.getCount()){ try { //song_sum = mTrackCursor.getCount(); // Amount = "("+song_current+"/"+mTrackCursor.getCount()+")"; long[] list = MusicUtils.getSongListForCursor(mTrackCursor); mService.resetList(list); } catch (RemoteException ex) { } } if(!mService.isPlaying() && DEVICE && mTrackCursor.getCount() != 0) { MusicUtils.playAll(MediaPlaybackActivity.this, mTrackCursor, 0); DEVICE = false; } } catch (RemoteException e) { Log.i("my", "///////RemoteException///////"); e.printStackTrace(); } Amount = "("+song_current+"/"+mTrackCursor.getCount()+")"; mPlay_item.setText(Amount); } }; private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { if(msg.what == 100) MusicUtils.FLAG = true; if(msg.what == 1) { try { if(mService.getPlayListLen() == mTrackCursor.getCount()) { // Long id = mSharedPreference.getLong(KEY_PATH_MEMORY_ID, 0); String path = mSharedPreference.getString(KEY_PLAY_PATH, ""); mTrackCursor.moveToFirst(); while (!mTrackCursor.isAfterLast()) { String artist = mTrackCursor.getString(mTrackCursor.getColumnIndexOrThrow( MediaStore.Audio.Media.DATA)); // long arttstId = mTrackCursor.getLong(mTrackCursor.getColumnIndexOrThrow( // MediaStore.Audio.Media._ID)); //Log.i("my", arttstId+"----------------MediaStore.Audio.Media.ARTIST_ID---------"); if (path.equals(artist)) { int inx = mTrackCursor.getPosition(); MusicUtils.playAll(MediaPlaybackActivity.this, mTrackCursor,inx); mService.seek(mSharedPreference.getLong(KEY_PLAY_TIME, 1000)); break; } mTrackCursor.moveToNext(); if(mTrackCursor.isAfterLast()) MusicUtils.playAll(MediaPlaybackActivity.this, mTrackCursor, 0); } } } catch (Exception e) { } } } }; private Handler mReScanHandler = new Handler() { @Override public void handleMessage(Message msg) { if (mAdapter != null) { String pa = "'%"+mounted_path+"%'"; getTrackCursor1( null, true,pa); } } }; public void init(Cursor newCursor, boolean isLimited) { if (mAdapter == null) { return; } // mAdapter.changeCursor(newCursor); // also sets mTrackCursor if (mTrackCursor == null) { MusicUtils.displayDatabaseError(this); closeContextMenu(); mReScanHandler.sendEmptyMessageDelayed(0, 1000); return; } // MusicUtils.hideDatabaseError(this); IntentFilter f = new IntentFilter(); f.addAction(MediaPlaybackService.META_CHANGED); f.addAction(MediaPlaybackService.QUEUE_CHANGED); String key = getIntent().getStringExtra("artist"); if (key != null) { int keyidx = mTrackCursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID); mTrackCursor.moveToFirst(); while (!mTrackCursor.isAfterLast()) { String artist = mTrackCursor.getString(keyidx); if (artist.equals(key)) { // setSelection(mTrackCursor.getPosition()); break; } mTrackCursor.moveToNext(); } } registerReceiver(mTrackListListener, new IntentFilter(f)); mTrackListListener.onReceive(this, new Intent( MediaPlaybackService.META_CHANGED)); song_sum = newCursor.getCount(); if(mPlay_item!=null) mPlay_item.setText("("+song_current+"/"+song_sum+")"); try { long[] list = MusicUtils.getSongListForCursor(mTrackCursor); if(mService!=null) mService.resetList(list); } catch (RemoteException e) { e.printStackTrace(); } } private BroadcastReceiver mTrackListListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mTrackList.invalidateViews(); } }; public ListView.OnItemClickListener Listener = new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // mTrackCursor.moveToPosition(arg2); //Cursor cursor = (Cursor) mTrackCursor.getItemAtPosition(arg2); //int personid = mTrackCursor.getInt(mTrackCursor.getColumnIndex("_id")); mAdapter.setSelect(arg2); mAdapter.notifyDataSetChanged(); if (!getIsAvailable()) { return; } if (mTrackCursor.getCount() == 0) { return; } MusicUtils.playAll(MediaPlaybackActivity.this, mTrackCursor, arg2); } }; @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { switch (requestCode) { case SCAN_DONE: if (resultCode == RESULT_CANCELED) { finish(); } else { getTrackCursor( null, true); } break; } } private Cursor getTrackCursor1( String filter, boolean async,String state) { // if (queryhandler == null) { // throw new IllegalArgumentException(); // } currentpath = state; //Cursor ret = null; Log.i("my", "----------state------------"+state); mSortOrder = MediaStore.Audio.Media._ID; StringBuilder where = new StringBuilder(); where.append(MediaStore.Audio.Media.TITLE + " != ''"); where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1"); where.append(" AND " + MediaStore.Audio.Media.DATA + " like "+state); if(SUM)where.append(" AND " + MediaStore.Audio.Media.SIZE + "="+main_path); Uri uri = MyUsers.User.CONTENT_URI; // MyUsers.User.CONTENT_URI // if (!TextUtils.isEmpty(filter)) { // uri = uri.buildUpon() // .appendQueryParameter("filter", Uri.encode(filter)).build(); // } try { Log.i("my", ":err<<<<<---------1---------"); ListCursor = MusicUtils.query(MediaPlaybackActivity.this, uri, mCursorCols, where.toString(), null, mSortOrder); Log.i("my", ":err<<<<<---------2---------"); } catch (Exception e) { e.printStackTrace(); } if(ListCursor != null && ListCursor.getCount() != 0) { init(ListCursor, false); songfile.clear(); while(ListCursor.moveToNext()){ String _data = ListCursor.getString(ListCursor.getColumnIndex("_data")); songfile.add(_data); } main_path = "123"; SUM = false; mAdapter.notifyDataSetChanged(); mTrackCursor = ListCursor; }else{ mReScanHandler.sendEmptyMessageDelayed(0, 1000); Log.i("my", ":err<<<<<---------3---------"); } return ListCursor; } private Cursor getTrackCursor( String filter, boolean async) { // if (queryhandler == null) { // throw new IllegalArgumentException(); // } //Cursor ret = null; mSortOrder = MediaStore.Audio.Media._ID; StringBuilder where = new StringBuilder(); where.append(MediaStore.Audio.Media.TITLE + " != ''"); where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1"); Uri uri = MyUsers.User.CONTENT_URI; // if (!TextUtils.isEmpty(filter)) { // uri = uri.buildUpon() // .appendQueryParameter("filter", Uri.encode(filter)).build(); // } Log.i("my", ":err<<<<<---------4---------"); ListCursor = MusicUtils.query(MediaPlaybackActivity.this, uri, mCursorCols, where.toString(), null, mSortOrder); if(ListCursor == null) return null; init(ListCursor, false); songfile.clear(); while(ListCursor.moveToNext()){ String _data = ListCursor.getString(ListCursor.getColumnIndex("_data")); songfile.add(_data); } mAdapter.notifyDataSetChanged(); //mAdapter = new TrackListAdapter(MediaPlaybackActivity.this,getApplication(),songfile); //mTrackList.setAdapter(mAdapter); mTrackCursor = ListCursor; return ListCursor; } public class TrackListAdapter extends BaseAdapter { private List<String> mList; private Context mContext; public int mSelectIdx; private List<String> _data = null; public TrackListAdapter(MediaPlaybackActivity mActivity,Context context, List<String> list) { mContext = context; mList = list; mSelectIdx = -1; _data = list; } public void setSelect(int index){ mSelectIdx = index; } public int getCount() { // TODO Auto-generated method stub return _data.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return _data.get(position); } public long getItemId(int position) { // TODO Auto-generated method stub return position; } public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub AppItem appItem; if (convertView == null) { View v = LayoutInflater.from(mContext).inflate(R.layout.track_list_item, null); appItem = new AppItem(); appItem.line1 = (TextView)v.findViewById(R.id.line1); appItem.number = (TextView)v.findViewById(R.id.song_number); appItem.ba = (ImageView)v.findViewById(R.id.musiclist_backimage); v.setTag(appItem); convertView = v; } else { appItem = (AppItem)convertView.getTag(); } Log.i("TT","position="+position+"---mList="+mList.get(position)); int start = mList.get(position).lastIndexOf("/")+1; int end = mList.get(position).lastIndexOf("."); if(end < 0) appItem.line1.setText(mList.get(position)); appItem.line1.setText(_data.get(position).substring(start, end)); appItem.number.setText((position+1)+"."); if(mSelectIdx == position ){ appItem.ba.setVisibility(View.VISIBLE); }else{ appItem.ba.setVisibility(View.INVISIBLE); } return convertView; } class AppItem { TextView line1; TextView number; ImageView ba; } } // TrackListAdapter(Context context, MediaPlaybackActivity currentactivity, // int layout, Cursor cursor, String[] from, int[] to, // boolean isnowplaying, boolean disablenowplayingindicator) { // super(context, layout, cursor, from, to, -1); // mActivity = currentactivity; // getColumnIndices(cursor); // mIsNowPlaying = isnowplaying; // mDisableNowPlayingIndicator = disablenowplayingindicator; // mUnknownArtist = context.getString(R.string.unknown_artist_name); // mUnknownAlbum = context.getString(R.string.unknown_album_name); // // mQueryHandler = new TrackQueryHandler(context.getContentResolver()); // mSelectIdx = -1; // } // // public void setSelect(int index){ // mSelectIdx = index; // } // // public void setActivity(MediaPlaybackActivity newactivity) { // mActivity = newactivity; // } // // public TrackQueryHandler getQueryHandler() { // return mQueryHandler; // } // // private void getColumnIndices(Cursor cursor) { // if (cursor != null) { // mTitleIdx = cursor // .getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE); // mArtistIdx = cursor // .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST); // mDurationIdx = cursor // .getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION); // try { // mAudioIdIdx = cursor // .getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID); // } catch (IllegalArgumentException ex) { // mAudioIdIdx = cursor // .getColumnIndexOrThrow(MediaStore.Audio.Media._ID); // } // } // } // // @Override // public View newView(Context context, Cursor cursor, ViewGroup parent) { // View v = super.newView(context, cursor, parent); // // ImageView iv = (ImageView) v.findViewById(R.id.icon); // // iv.setVisibility(View.GONE); // // ViewHolder vh = new ViewHolder(); // vh.number = (TextView) v.findViewById(R.id.song_number); // vh.line1 = (TextView) v.findViewById(R.id.line1); // //vh.line2 = (TextView) v.findViewById(R.id.line2); // vh.ba = (ImageView) v.findViewById(R.id.musiclist_backimage); // //vh.duration = (TextView) v.findViewById(R.id.duration); // // vh.play_indicator = (ImageView) v.findViewById(R.id.play_indicator); // vh.buffer1 = new CharArrayBuffer(100); // vh.buffer2 = new char[200]; // v.setTag(vh); // return v; // } // // @Override // public void bindView(View view, Context context, Cursor cursor) { // ViewHolder vh = (ViewHolder) view.getTag(); // // cursor.copyStringToBuffer(mTitleIdx, vh.buffer1); // vh.number.setText(String.valueOf(cursor.getPosition()+1)+"."); // vh.line1.setText(vh.buffer1.data, 0, vh.buffer1.sizeCopied); // // int secs = cursor.getInt(mDurationIdx) / 1000; // if (secs == 0) { // //vh.duration.setText(""); // } else { // //vh.duration.setText(MusicUtils.makeTimeString(context, secs)); // } // // final StringBuilder builder = mBuilder; // builder.delete(0, builder.length()); // // String name = cursor.getString(mArtistIdx); // if (name == null || name.equals(MediaStore.UNKNOWN_STRING)) { // builder.append(mUnknownArtist); // } else { // builder.append(name); // } // int len = builder.length(); // if (vh.buffer2.length < len) { // vh.buffer2 = new char[len]; // } // builder.getChars(0, len, vh.buffer2, 0); // //vh.line2.setText(vh.buffer2, 0, len); // // // if(mSelectIdx == cursor.getInt(cursor.getColumnIndex("_id")) ){ // vh.ba.setVisibility(View.VISIBLE); // }else{ // vh.ba.setVisibility(View.INVISIBLE); // } // // } // // @Override // public void changeCursor(Cursor cursor) { // try { // if (mActivity.isFinishing() && cursor != null) { // cursor.close(); // cursor = null; // } // if (cursor != mActivity.mTrackCursor) { // mActivity.mTrackCursor = cursor; // super.changeCursor(cursor); // getColumnIndices(cursor); // } // } catch (StaleDataException e) { // e.printStackTrace(); // } // } // // @Override // public Cursor runQueryOnBackgroundThread(CharSequence constraint) { // String s = constraint.toString(); // if (mConstraintIsValid // && ((s == null && mConstraint == null) || (s != null && s // .equals(mConstraint)))) { // return getCursor(); // } // Cursor c = mActivity.getTrackCursor(mQueryHandler, s, false); // mConstraint = s; // mConstraintIsValid = true; // return c; // } // // } private void resetStatusBarBackground(int color) { if (mStatusbarService != null) { try { if (mStatusBarManager == null) { mStatusBarManager = Class .forName("android.app.StatusBarManager"); mMethod = mStatusBarManager.getMethod("resetBackground", int.class); } if (mMethod != null) { mMethod.invoke(mStatusbarService, color); } } catch (Exception e) { mStatusBarManager = null; mMethod = null; e.printStackTrace(); } } } private boolean getIsAvailable() { Parcel reply = Parcel.obtain(); if (mCbmCtx == null) { mCbmCtx = new CBMCtx(); } mCbmCtx.query(reply); int souce_count = reply.readInt(); Log.d(LOGTAG, "rds --------souce_count="+souce_count); for (int i = 0; i < souce_count; i++) { int t = reply.readInt(); Log.d(LOGTAG, "rds --------souce="+t); if (CBMCtx.SRC_AVIN_A_RDS == t) { reply.recycle(); return false; } } reply.recycle(); return true; } private OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() { public void onStartTrackingTouch(SeekBar bar) { mLastSeekEventTime = 0; mFromTouch = true; } public void onProgressChanged(SeekBar bar, int progress, boolean fromuser) { //if (!getIsAvailable()) { // return; // } if (!fromuser || (mService == null)) return; long now = SystemClock.elapsedRealtime(); if ((now - mLastSeekEventTime) > 1) { mLastSeekEventTime = now; mPosOverride = mDuration * progress / 1000; } } public void onStopTrackingTouch(SeekBar bar) { try { mService.seek(mPosOverride); if (mLyric != null) { int line = getLrcLine(mService.position()); mLrcView.setlrc(line); } // trackball event, allow progress updates if (!mFromTouch) { refreshNow(); mPosOverride = -1; } } catch (RemoteException ex) { } mPosOverride = -1; mFromTouch = false; } }; private void onPlaypauseButton() { if (!getIsAvailable()) { return; } doPauseResume(); } private void onPrevButton() { if (!getIsAvailable()) { return; } Message msg = mHandler.obtainMessage(PREV_BUTTON_CLICK); mHandler.removeMessages(PREV_BUTTON_CLICK); mHandler.sendMessage(msg); } private void onNextButton() { if (!getIsAvailable()) { return; } Message msg = mHandler.obtainMessage(NEXT_BUTTON_CLICK); mHandler.removeMessages(NEXT_BUTTON_CLICK); mHandler.sendMessage(msg); } private void onFBButton() { try { if (!getIsAvailable()) { return; } if (mService == null || !mService.isPlaying()) { Log.d(LOGTAG, "rewind button onclick--------leave"); return; } int rateBkp = mCurPlaybackRate; mCurPlaybackRate = PLAYBACK_RATE_NORMAL; if (rateBkp < 0) { if (Math.abs(rateBkp) < PLAYBACK_RW_RATE_MAX) { mCurPlaybackRate = (rateBkp << 1); } } else if (PLAYBACK_RW_RATE_MAX > 1) { mCurPlaybackRate = (PLAYBACK_RATE_NORMAL << 1) * -1; } mCurPlaybackRate = setPlaybackRate(mCurPlaybackRate); updateTitleIconPlayState(PlayStatus.STATUS_PLAY); Log.d(LOGTAG, "rewind button onclick--------leave"); } catch (RemoteException e) { e.printStackTrace(); } } private void onFFButton() { try { if (!getIsAvailable()) { return; } if (mService == null || !mService.isPlaying()) { Log.d(LOGTAG, "fastforward button onclick--------leave"); return; } int rateBkp = mCurPlaybackRate; if (rateBkp >= PLAYBACK_FF_RATE_MAX) { mCurPlaybackRate = PLAYBACK_RATE_NORMAL; } else if (rateBkp < 0) { if (PLAYBACK_FF_RATE_MAX > 1) { mCurPlaybackRate = (PLAYBACK_RATE_NORMAL << 1); } else { mCurPlaybackRate = PLAYBACK_RATE_NORMAL; } } else { mCurPlaybackRate = (rateBkp << 1); } mCurPlaybackRate = setPlaybackRate(mCurPlaybackRate); updateTitleIconPlayState(PlayStatus.STATUS_PLAY); Log.d(LOGTAG, "fastforward button onclick--------leave"); } catch (RemoteException e) { e.printStackTrace(); } } private void onStopButton() { if (!getIsAvailable()) { return; } doStopResume(); } private void onRepeatButton() { if (!getIsAvailable()) { return; } cycleRepeat(); } //锟截革拷 private View.OnClickListener mRepeatListener = new View.OnClickListener() { public void onClick(View v) { onRepeatButton(); } }; //音效 private View.OnClickListener mEqListener = new View.OnClickListener() { public void onClick(View v) { basse++; if(basse == 7) basse = 0; //setEQDry(basse); mEqButton.setText(eq[basse]); mEditor.putInt("BASSE", basse); mEditor.commit(); if (null == gMCM) gMCM = new McuComManager(); if (null != gMCM) gMCM.setEQMode(basse); sendBroadcast(new Intent("com.android.jbd.equsermode")); } }; //停止 private View.OnClickListener mStopListener = new View.OnClickListener() { public void onClick(View v) { onStopButton(); } }; //锟斤拷停 private View.OnClickListener mPauseListener = new View.OnClickListener() { public void onClick(View v) { if(ENABLED)onPlaypauseButton(); } }; //锟斤拷一锟斤拷 private View.OnClickListener mPrevListener = new View.OnClickListener() { public void onClick(View v) { try { if(mService.getShuffleMode() == MediaPlaybackService.SHUFFLE_NORMAL) { if(ENABLED) onNextButton(); }else{ if(ENABLED)onPrevButton(); } } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; //锟斤拷一锟斤拷 private View.OnClickListener mNextListener = new View.OnClickListener() { public void onClick(View v) { if(ENABLED) onNextButton(); } }; private void doPrevButtonAction() { Log.d(LOGTAG, "prev button onclick--------enter"); if (mService == null) { Log.d(LOGTAG, "prev button onclick--------leave"); return; } try { // if (mService.position() < 2000) { mService.prev(); // } else { // mService.seek(0); // mService.play(); // } } catch (RemoteException ex) { } Log.d(LOGTAG, "prev button onclick--------leave"); } private void doNextButtonAction() { Log.d(LOGTAG, "next button onclick--------enter"); if (mService == null) { Log.d(LOGTAG, "next button onclick--------leave"); return; } try { mService.next(); } catch (RemoteException ex) { } Log.d(LOGTAG, "next button onclick--------leave"); } //dellete song private View.OnClickListener mMuteListener = new View.OnClickListener() { public void onClick(View v) { byte[] mute = McuComKey.getKeyData( McuComKey.CAR_KEY_ATTR_TOUCH, McuComKey.SHORTKEY, McuComKey.CAR_KEY_AUDIO_MUTE); send_command(McuComAddr.CAR_MPEG_KEY_ADR, mute); // try { // long mSelectedId = 0; // String mCurrentTrackName = null; // mSelectedDelete = mService.getQueuePosition(); // mTrackCursor.moveToPosition(mSelectedDelete); // mCurrentTrackName = mTrackCursor.getString(mTrackCursor.getColumnIndexOrThrow( // MediaStore.Audio.Media.TITLE)); // try { // int id_idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID); // mSelectedId = mTrackCursor.getLong(id_idx); // } catch (IllegalArgumentException ex) { // //.... // } // // long[] list = new long[1]; // list[0] = mSelectedId; // Log.i("my", String.valueOf(list[0])+""); // String f = getString(R.string.delete_single_medif_file_desc); // String desc = String.format(f, mCurrentTrackName); // // Bundle b = new Bundle(); // b.putString("description", desc); // b.putLongArray("items", list); // Intent intent = new Intent(); // intent.setClass(MediaPlaybackActivity.this, DeleteItemActivity.class); // intent.putExtras(b); // startActivityForResult(intent, -1); // // } catch (Exception e) { // e.printStackTrace(); // } } }; public void setEQDry(int value) { int[] EQGain = new int[11]; for (int idx = 0; idx < 11; idx++) { int temp = 0; if (idx >= 1 && idx <= 3) { temp = Array.gEQTypePos[value][idx]; } else if (idx >= 8 && idx <= 10) { temp = Array.gEQTypePos[value][idx]; } else { temp = Array.gEQTypePos[value][idx]; } if (temp > 14) { temp = 14; } else if (temp < -14) { temp = -14; } if (idx == 0) { EQGain[idx] = Array.g_dryValues[temp + 14]; } else { EQGain[idx] = Array.g_ganValues[temp + 14]; } } AtcSettings.Audio.SetEQValues(EQGain);// 淇敼 } private View.OnClickListener list_Listener = new View.OnClickListener() { public void onClick(View v) { switch (v.getId()) { case R.id.hide_list: if(mTrackList.getVisibility() == View.GONE) { mTrackList.setVisibility(View.VISIBLE); if(equlizer.getVisibility() == View.VISIBLE) equlizer.setVisibility(View.GONE); }else{ mTrackList.setVisibility(View.GONE); } break; case R.id.equalizer: if(equlizer.getVisibility() == View.GONE) { equlizer.setVisibility(View.VISIBLE); if(mTrackList.getVisibility() == View.VISIBLE) mTrackList.setVisibility(View.GONE); }else{ equlizer.setVisibility(View.GONE); } break; default: break; } } }; //browse song private View.OnClickListener mbrowseListener = new View.OnClickListener() { public void onClick(View v) { //Intent intent = new Intent(); //intent.setClass(MediaPlaybackActivity.this,TrackListActivity.class); //startActivityForResult(intent, 1); try { mTrackCursor.moveToPosition(mService.getQueuePosition()); String url = mTrackCursor.getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); String playerpath = url.subSequence(0, 11).toString(); Bundle b = new Bundle(); b.putString("PLAYERPATH", playerpath); Intent intent = new Intent(); intent.setClass(MediaPlaybackActivity.this, FolderListActivity.class); intent.putExtras(b); startActivityForResult(intent, 1); } catch (Exception e) { } } }; @Override public void onStart() { Log.d(LOGTAG, "onStart--------leave"); super.onStart(); } @Override public void onNewIntent(Intent intent) { setIntent(intent); } public void getCursor(String path) { if(!path.equals("")) { mounted_path = path; getTrackCursor1(null, true,"'%"+path+"%'"); } } @Override public void onResume() { Log.d("my", "onResume--------leave"); super.onResume(); MusicUtils.FLAG = true; if (null != gMCM) { g_sys_state = gMCM.getSystemState(); if(g_sys_state!=McuComSysState.CAR_MPEG_SYS_POWEROFF) { if(g_sys_state != McuComSysState.CAR_MPEG_SYS_SD) { g_sys_state = McuComSysState.CAR_MPEG_SYS_SD; gMCM.setSystemState(g_sys_state); byte[] data = McuComKey.getKeyData( McuComKey.CAR_KEY_ATTR_TOUCH, McuComKey.SHORTKEY, McuComKey.CAR_KEY_SD_SEL); send_command(McuComAddr.CAR_MPEG_KEY_ADR, data); } gMCM.setMcuComClient(); gMCM.setOnActionListener(mAudioAction); basse = gMCM.getEQMode(); mEqButton.setText(eq[basse]); } } Intent intent2 = new Intent(); intent2.setAction("com.android.launcher.showstate"); intent2.putExtra("cur_state_off", 0); sendBroadcast(intent2); // if(!((MusicApplication) getApplication()).get_Play().equals("")) // { // getTrackCursor1( null, true,((MusicApplication) getApplication()).get_Play()); // ((MusicApplication) getApplication()).set_Play(""); // mAdapter.setSelect(((MusicApplication) getApplication()).songNum); // //mAdapter.notifyDataSetChanged(); // } // if(((MusicApplication) getApplication()).all_song == 1) // { // getTrackCursor( null, true); // ((MusicApplication) getApplication()).setState(0); // mAdapter.setSelect(((MusicApplication) getApplication()).songNum); // //mAdapter.notifyDataSetChanged(); // } Log.d(LOGTAG, "onStart--------leave1"); paused = false; mToken = MusicUtils.bindToService(this, osc); if (mToken == null) { // something went wrong mHandler.sendEmptyMessage(QUIT); } try { updateTrackInfo(); long next = refreshNow(); queueNextRefresh(next); } catch (Exception e) { e.printStackTrace(); } Log.d(LOGTAG, "onStart--------leave2"); //------------------------------start updateTrackList(); MusicUtils.setSpinnerState(this); doActivityResume(); if (BaseRearManager.IS_REAR_OPENING && mRearManager.getRearPresentation() == null) { mRearManager.openRear(); openRearAudio(); } mHandler.removeMessages(MSG_SET_STATUSBAR_BACKGROUND); mHandler.sendEmptyMessageDelayed(MSG_SET_STATUSBAR_BACKGROUND, 400); Log.d(LOGTAG, "onResume--------enter"); try { updateTrackInfo(); setPauseButtonImage(); } catch (Exception e) { e.printStackTrace(); } Log.d(LOGTAG, "onResume--------leave"); } private void doActivityResume() { Log.d("LOGTAG", "doActivityResume--------mService=" + mService); if (mService == null) { return; } if (MediaPlaybackService.IS_FIRST_RESUME_AFTER_SUSPENDED) { MediaPlaybackService.IS_FIRST_RESUME_AFTER_SUSPENDED = false; if (MediaPlaybackActivity.LAST_PLAYBACK_STATUS == AtcMediaPlayer.MEDIA_PLAYER_STARTED) { try { if (MediaPlaybackService.PLAYBACK_STATUS_WHEN_POWEROFF != AtcMediaPlayer.MEDIA_PLAYER_STARTED) { Intent intent = new Intent( MediaPlaybackService.ACTION_RESUME_PLAYBACK); intent.putExtra("seek", SAVE_PROGRESS); sendBroadcast(intent); MediaPlaybackService.PLAYBACK_STATUS_WHEN_POWEROFF = AtcMediaPlayer.MEDIA_PLAYER_STOPPED; return; } } catch (Exception e) { e.printStackTrace(); } } } try { startPlayback(); // Assume something is playing when the service says it is, // but also if the audio ID is valid but the service is paused. if (mService.getAudioId() >= 0 || mService.isPlaying() || mService.getPath() != null) { if (mService.isPlaying()) { LAST_PLAYBACK_STATUS = AtcMediaPlayer.MEDIA_PLAYER_STARTED; updateFastforwardAndRewindButtonState(mService); } initLrc(); link(mService.getAudioSessionId()); setPauseButtonImage(); updateTitleIconPlayState(PlayStatus.STATUS_PLAY); Log.d(LOGTAG, "doActivityResume--------leave=2"); return; } } catch (RemoteException ex) { } } @Override public void onPause() { Log.d("my", "onPause--------leave"); MusicUtils.FLAG = false;//add //--------------------------------------1 // if (mVisualizer != null) { // mVisualizer.release(); // mVisualizer = null; // } // mAlbumArtWorker.quit(); //-------------------------------start mReScanHandler.removeCallbacksAndMessages(null); //-----------------------------------------------------1 resetStatusBarBackground(Color.BLACK); super.onPause(); } @Override public void onStop() { Log.d("my", "onStop--------leave"); paused = true; super.onStop(); Log.d(LOGTAG, "onStop--------leave"); } @Override public void onDestroy() { if(Scanner != null) { Scanner.interrupt(); Scanner = null; } if (mVisualizer != null) { mVisualizer.release(); mVisualizer = null; } mSpectrumView = null; if (null != gMCM) gMCM.setSysScanDevFlag(0); MediaPlaybackService.PlayState = false; SaveState(); //------------------start Log.d("my", "onDestroy--------leave"); //-------------------------------------------1 //((MusicApplication) getApplication()).set_Play(""); //MusicUtils.FLAG = false; if(DESTROY){ onStopButton(); MusicUtils.unbindFromService(mToken1); mHandler.removeMessages(REFRESH); MusicUtils.unbindFromService(mToken); mService = null; /* try { unregisterReceiverSafe(mTrackListListener); unregisterReceiverSafe(mScanListener); unregisterReceiver(mCbmListener); unregisterReceiver(mQuickBootListener); unregisterReceiver(mStatusListener); unregisterReceiver(mStartPlayListener); unregisterReceiver(mStartPlay); } catch (IllegalArgumentException ex) { // ignore }*/ if (!mAdapterSent && mAdapter != null) { // mAdapter.changeCursor(null); } //---------------------------------------------1 paused = true; mHandler.removeMessages(REFRESH); gMCM.sendMcuComCanBusStr("Music"); mRearManager.closeRear(); closeRearAudio(); mam.finishAllActivity(); } try { unregisterReceiverSafe(mTrackListListener); unregisterReceiverSafe(mScanListener); unregisterReceiver(mCbmListener); unregisterReceiver(mQuickBootListener); unregisterReceiver(mStatusListener); unregisterReceiver(mStartPlayListener); unregisterReceiver(mStartPlay); } catch (IllegalArgumentException ex) { // ignore } super.onDestroy(); } //锟斤拷停--锟街革拷 private void doPauseResume() { try { if (mService != null) { if (mService.isPlaying()) { mService.pause(); LAST_PLAYBACK_STATUS = AtcMediaPlayer.MEDIA_PLAYER_PAUSED; updateTitleIconPlayState(PlayStatus.STATUS_PAUSE); refreshNow(); } else { if (mCurPlaybackRate != PLAYBACK_RATE_NORMAL) { mCurPlaybackRate = setPlaybackRate(PLAYBACK_RATE_NORMAL); } if (mService.duration() == -1) { mService.rePlay(); LAST_PLAYBACK_STATUS = AtcMediaPlayer.MEDIA_PLAYER_STARTED; if (mVisualizer == null) { link(mService.getAudioSessionId()); } mHandler.sendEmptyMessage(REFRESH); } else { mService.play(); LAST_PLAYBACK_STATUS = AtcMediaPlayer.MEDIA_PLAYER_STARTED; refreshNow(); } updateTitleIconPlayState(PlayStatus.STATUS_PLAY); mProgress.setEnabled(true); } setPauseButtonImage(); } } catch (RemoteException ex) { } } //停止--锟街革拷 private void doStopResume() { try { if (mService != null) { mService.stop(); LAST_PLAYBACK_STATUS = -1; mLrcView.setlrc(0); updateTitleIconPlayState(PlayStatus.STATUS_STOP); mHandler.removeMessages(REFRESH); mProgress.setProgress(0); mProgress.setEnabled(false); mCurrentTime.setText("00:00"); mCurrentTime.setVisibility(View.VISIBLE); mLrcView.noLrc(getString(R.string.mmp_info_nolrc)); setPauseButtonImage(); refreshRearView(mCurrentTime); refreshRearView(mProgress); refreshRearView(mLrcView); } } catch (RemoteException ex) { } } //锟斤拷锟斤拷状态 private void updateTitleIconPlayState(PlayStatus playStatus) { mIvTitleIconInfo.setText(""); int icon = R.drawable.mm_icon_play; switch (playStatus) { case STATUS_STOP: icon = R.drawable.mm_icon_stop; break; case STATUS_PAUSE: icon = R.drawable.mm_icon_pause; break; case STATUS_PLAY: // -- if (mCurPlaybackRate < 0) { icon = R.drawable.mm_icon_rw; } else if (mCurPlaybackRate > 1) { icon = R.drawable.mm_icon_ff; } else { icon = R.drawable.mm_icon_play; } if (Math.abs(mCurPlaybackRate) == 1) { mIvTitleIconInfo.setText(""); } else { mIvTitleIconInfo.setText(Math.abs(mCurPlaybackRate) + "x"); } // -- break; default: break; } if (icon == R.drawable.mm_icon_rw || icon == R.drawable.mm_icon_ff) { mIvTitlePlayIcon.setVisibility(View.VISIBLE); mIvTitlePlayIcon.setImageResource(icon); mIvTitlePlayIcon.setTag(icon); } else { mIvTitlePlayIcon.setVisibility(View.INVISIBLE); mIvTitlePlayIcon.setImageResource(R.drawable.mm_icon_play); mIvTitlePlayIcon.setTag(R.drawable.mm_icon_play); } refreshRearView(mIvTitleIconInfo); refreshRearView(mIvTitlePlayIcon); } private void updateFastforwardAndRewindButtonState( IMediaPlaybackService service) { if (service == null) { return; } //mButtonRW.setEnabled(true); //mButtonFF.setEnabled(true); long mediaCapability = 0x3FFFFFFF; try { if (mService != null && mService.duration() > -1) { mediaCapability = mService.getCapability(); } } catch (RemoteException ex) { ex.printStackTrace(); } if ((mediaCapability & CAP_FILE_FF_UNSUPPORT) != 0 || PLAYBACK_FF_RATE_MAX < 2) { // mButtonFF.setEnabled(false); } if ((mediaCapability & CAP_FILE_RW_UNSUPPORT) != 0 || PLAYBACK_RW_RATE_MAX < 2) { //mButtonRW.setEnabled(false); } } private void cycleRepeat() { if (mService == null) { return; } try { int mode = mService.getRepeatMode(); if (mService.getShuffleMode() == MediaPlaybackService.SHUFFLE_NORMAL) { mService.setRepeatMode(MediaPlaybackService.REPEAT_ALL); mService.setShuffleMode(MediaPlaybackService.SHUFFLE_NONE); //showToast(R.string.repeat_all_notif); } else if (mode == MediaPlaybackService.REPEAT_NONE) { mService.setRepeatMode(MediaPlaybackService.REPEAT_ALL); //showToast(R.string.repeat_all_notif); } else if (mode == MediaPlaybackService.REPEAT_ALL) { mService.setRepeatMode(MediaPlaybackService.REPEAT_CURRENT); if (mService.getShuffleMode() != MediaPlaybackService.SHUFFLE_NONE) { mService.setShuffleMode(MediaPlaybackService.SHUFFLE_NONE); // setShuffleButtonImage(); } //showToast(R.string.repeat_current_notif); } else if (mode == MediaPlaybackService.REPEAT_CURRENT) { mService.setShuffleMode(MediaPlaybackService.SHUFFLE_NORMAL); mService.setRepeatMode(MediaPlaybackService.REPEAT_ALL); //showToast(R.string.random_all_notif); } else { mService.setRepeatMode(MediaPlaybackService.REPEAT_NONE); //showToast(R.string.repeat_off_notif); } setRepeatButtonImage(); } catch (RemoteException ex) { } } private void showToast(int resid) { if (mToast == null) { mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); } mToast.setText(resid); mToast.show(); } private void initRepeatMode() { if (mService == null) return; try { int shuffle = mService.getShuffleMode(); int mode = mService.getRepeatMode(); if (shuffle == MediaPlaybackService.SHUFFLE_NONE && mode != MediaPlaybackService.REPEAT_ALL && mode != MediaPlaybackService.REPEAT_CURRENT) { mService.setRepeatMode(MediaPlaybackService.REPEAT_ALL); mService.setShuffleMode(MediaPlaybackService.SHUFFLE_NONE); } } catch (RemoteException e) { e.printStackTrace(); } setRepeatButtonImage(); } private void startPlayback() { if (mService == null) return; Intent intent = getIntent(); String filename = ""; Uri uri = intent.getData(); if (uri != null && uri.toString().length() > 0) { // If this is a file:// URI, just use the path directly instead // of going through the open-from-filedescriptor codepath. String scheme = uri.getScheme(); if ("file".equals(scheme)) { filename = uri.getPath(); } else { filename = uri.toString(); } try { mService.stop(); mService.openFile(filename); mService.play(); setIntent(new Intent()); // initRepeatMode(); } catch (Exception ex) { Log.d("MediaPlaybackActivity", "couldn't start playback: " + ex); } } try { initRepeatMode(); mProgress.setEnabled(true); updateTrackInfo(); long next = refreshNow(); queueNextRefresh(next); } catch (Exception e) { e.printStackTrace(); } } public int getLrcLine(long time) { if (mLyric != null) { return mLyric.getLine(time); } else { return 0; } } private void initLrc() { lrc_map = getLrcInfo(); if (lrc_map != null) { mLrcView.init(lrc_map, 7); mHandler.sendEmptyMessageDelayed(REFRESH_LYRIC, 2000); } else { lrc_map = null; mHandler.removeMessages(REFRESH_LYRIC); mLrcView.noLrc(getString(R.string.mmp_info_nolrc)); } refreshRearView(mLrcView); } public Vector<LyricTimeContentInfo> getLrcInfo() { Vector<LyricTimeContentInfo> lrcInfo = null; mfilepath = null; String mp3Path = mfilepath; if (mfilepath == null) { try { if (mService == null) { return null; } String path = mService.getPath(); if (path == null) { return null; } else if (path.startsWith("content://")) { contentPathToUri(path); } else { mfilepath = path; } } catch (RemoteException e) { return null; } if (mfilepath == null) { return null; } mp3Path = mfilepath; Log.i(LOGTAG, "the path of file22::" + mfilepath + ":::weiyu2014"); } Log.i(LOGTAG, "the path of file11::" + mp3Path + ":::weiyu2014"); String lrcPath = null; try { lrcPath = mp3Path.substring(0, mp3Path.lastIndexOf('.')) + ".lrc"; } catch (Exception e) { return null; } Log.i(LOGTAG, "the path of file55::" + lrcPath + ":::weiyu2014"); // String lrcPath = mfilepath + ".lrc"; File lrcFile = new File(lrcPath); if (lrcFile.exists()) { mLyric = new Lyric(lrcPath); lrcInfo = mLyric.getLyricTimeContentInfo(); } else { mLyric = null; } return lrcInfo; } public void contentPathToUri(String path) { String myImageUrl; myImageUrl = path; Cursor actualimagecursor = null; try { Log.d(LOGTAG, "===contentPathToUri==="); Uri uri = Uri.parse(myImageUrl); String[] proj = { MediaStore.Images.Media.DATA }; actualimagecursor = getContentResolver().query(uri, proj, null, null, null); int actual_image_column_index = actualimagecursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); String img_path = actualimagecursor .getString(actual_image_column_index); actualimagecursor.close(); mfilepath = img_path; } catch (Exception e) { e.printStackTrace(); } finally { if (actualimagecursor != null) { actualimagecursor.close(); } } } private ServiceConnection osc = new ServiceConnection() { public void onServiceConnected(ComponentName classname, IBinder obj) { Log.d(LOGTAG, "ServiceConnection--------enter"); mService = IMediaPlaybackService.Stub.asInterface(obj); doActivityResume(); } public void onServiceDisconnected(ComponentName classname) { mService = null; } }; private void link(int audioSessionId) { if (mVisualizer == null) { Log.d(LOGTAG, "link--------new Visualizer"); mVisualizer = new Visualizer(audioSessionId); } try { mVisualizer.setCaptureSize(128); } catch (IllegalStateException e) { } catch (Exception e) { e.printStackTrace(); } // Pass through Visualizer data to VisualizerView Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener() { @Override public void onFftDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) { try { if (mService != null) { if (mService.isPlaying()) { if(mSpectrumView!=null)//kaicer add 20151216 { mSpectrumView.display(bytes); mSpectrumView.setTag(bytes); refreshRearView(mSpectrumView); } } else if (mService.duration() < 0) { if(mSpectrumView!=null)//kaicer add 20151216 mSpectrumView.display(null); } } } catch (RemoteException e) { e.printStackTrace(); } } @Override public void onWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate) { } }; if (mVisualizer != null) { mVisualizer.setDataCaptureListener(captureListener, Visualizer.getMaxCaptureRate() / 1, false, true); mVisualizer.setEnabled(true); } } //循锟斤拷 锟斤拷前/锟