Exemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题栏
    setContentView(R.layout.activity_local);

    intentFromMain = getIntent();
    Bundle bundle = intentFromMain.getExtras();
    listPosition = bundle.getInt("listPosition");
    play_bt_press = bundle.getBoolean("bt_press");
    play_bt_check = bundle.getBoolean("bt_check");
    isFirstTime = bundle.getBoolean("isFirstTime");
    isPlaying = bundle.getBoolean("isPlaying");
    isPause = bundle.getBoolean("isPause");
    msg = bundle.getInt("msg");

    preferences = getSharedPreferences("songPosition", MODE_PRIVATE);
    editor = preferences.edit();

    appState = ((MApplication) getApplicationContext());
    helper = appState.getDBHelper();
    helperFavorite = appState.getDBHelperFavorite();
    fileInfos = appState.getFileInfos();

    findViewById(); // 从界面上根据id获取控件
    setViewOnclickListener(); // 给每一个控件设置监听器
    initLocalMusicList(); // 初始化歌曲列表

    playerReceiver = new PlayerReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(PlayerService.UPDATE_ACTION);
    filter.addAction(PlayerService.MUSIC_PLAY_PAUSE);
    registerReceiver(playerReceiver, filter);
  }
Exemplo n.º 2
0
  @Override
  public void onCreate() {
    super.onCreate();
    mediaPlayer = new MediaPlayer();
    appState = ((MApplication) getApplicationContext());
    mp3Infos = appState.getFileInfos();
    // mp3Infos = MediaUtil.getFileInfos(PlayerService.this);

    // 设置音乐播放完成时的监听器
    mediaPlayer.setOnCompletionListener(
        new OnCompletionListener() {
          public void onCompletion(MediaPlayer mp) {
            if (status == 1) { // 单曲循环				
              play(0);
            } else if (status == 2) { // 全部循环
              current++;
              if (current > mp3Infos.size() - 1) { // 变为第一首的位置继续播放
                current = 0;
              }
              Intent sendIntent = new Intent(UPDATE_ACTION);
              sendIntent.putExtra("current", current);
              sendBroadcast(sendIntent);
              path = mp3Infos.get(current).getUrl();
              play(0);
            } else if (status == 3) { // 随机播放
              current = getRandomIndex(mp3Infos.size() - 1);
              Intent sendIntent = new Intent(UPDATE_ACTION);
              sendIntent.putExtra("current", current);
              sendBroadcast(sendIntent);
              path = mp3Infos.get(current).getUrl();
              play(0);
            }
          }
        });

    // 为多媒体数据库数据改变注册监听器
    getContentResolver()
        .registerContentObserver(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            true,
            new MusicDataObserver(new Handler()));

    // 广播接收器只接收CTL_ACTION控制动作
    myReceiver = new MyReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(CTL_ACTION);
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); // 媒体库更新
    registerReceiver(myReceiver, filter);
  }
Exemplo n.º 3
0
 @Override
 protected void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   appState = ((MApplication) getApplicationContext());
   helper = appState.getDBHelper();
   helperFavorite = appState.getDBHelperFavorite();
   fileInfos = appState.getFileInfos();
   music_play_bt.setPressed(play_bt_press);
   music_play_bt.setChecked(play_bt_check);
   setFavoriteDefault(); // 设置是否歌曲收藏状态
   if (anim != null && isPlaying == true) {
     if (!anim.isStarted()) {
       anim.start(); // 开始旋转
     } else {
       anim.resume(); // 继续旋转
     }
   } else {
     anim.pause(); // 停止旋转
   }
 }