Android Open Source - NPlayer Music Activity






From Project

Back to project page NPlayer.

License

The source code is released under:

Apache License

If you think the Android project NPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.qinxiandiqi.nplayer;
//from  w w  w .ja v a  2 s .c o m
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.qinxiandiqi.utils.CodeUtils;

public class MusicActivity extends Activity {

  private ImageButton startButton;
  private TextView musicTitle;
  private MusicActivityReceiver musicActivityReceiver;
  private Intent intentToMusicService;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_music);
    startButton = (ImageButton) findViewById(R.id.start);
    musicTitle = (TextView) findViewById(R.id.musictitle);
    musicActivityReceiver = new MusicActivityReceiver();
    IntentFilter filter = new IntentFilter(CodeUtils.MUSICACTION);
    registerReceiver(musicActivityReceiver, filter);
    intentToMusicService = new Intent();
    intentToMusicService.setAction(CodeUtils.MUSICSERVICEACTION);
    
    if(CodeUtils.playingMusic != CodeUtils.NOTNEXTONE){
      musicTitle.setText(CodeUtils.musicFileList.get(CodeUtils.playingMusic).getMediaName());
    }
    
    if(CodeUtils.playingMusicState == CodeUtils.PLAYING){
      startButton.setImageResource(R.drawable.playing);
    }
  }

  @Override
  protected void onPause() {
    CodeUtils.musicAdapter.notifyDataSetChanged();
    super.onPause();
  }
  
  @Override
  protected void onDestroy() {
    unregisterReceiver(musicActivityReceiver);
    super.onDestroy();
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    return true;
  }

//  ??????????
  public void forwardoneOnClick(View v){
    intentToMusicService.putExtra(CodeUtils.MEDIAOPCODE, CodeUtils.FORWARDONE);
    sendBroadcast(intentToMusicService);
  }
  
//  ?????????
  public void rewindOnClick(View v){
    intentToMusicService.putExtra(CodeUtils.MEDIAOPCODE, CodeUtils.REWIND);
    sendBroadcast(intentToMusicService);
  }
  
//  ?????????????
  public void startOnClick(View v){
    if(CodeUtils.playingMusicState == CodeUtils.PLAYING){
      intentToMusicService.putExtra(CodeUtils.MEDIAOPCODE, CodeUtils.PAUSE);
    }else{
      intentToMusicService.putExtra(CodeUtils.MEDIAOPCODE, CodeUtils.START);
    }
    sendBroadcast(intentToMusicService);
  }
  
//  ???????????
  public void stopOnClick(View v){
    intentToMusicService.putExtra(CodeUtils.MEDIAOPCODE, CodeUtils.STOP);
    sendBroadcast(intentToMusicService);
  }
  
//  ?????????
  public void fastforwardOnClick(View v){
    intentToMusicService.putExtra(CodeUtils.MEDIAOPCODE, CodeUtils.FASTFORWARD);
    sendBroadcast(intentToMusicService);
  }
  
//  ??????????
  public void nextoneOnClick(View v){
    intentToMusicService.putExtra(CodeUtils.MEDIAOPCODE, CodeUtils.NEXTONE);
    sendBroadcast(intentToMusicService);
  }
  
  public class MusicActivityReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
      switch (intent.getExtras().getInt(CodeUtils.MEDIAOPCODE)) {
      case CodeUtils.PLAYING:
        startButton.setImageResource(R.drawable.playing);
        musicTitle.setText(CodeUtils.musicFileList.get(CodeUtils.playingMusic).getMediaName());
        break;
      case CodeUtils.STOP:
        startButton.setImageResource(R.drawable.start);
        break;
      case CodeUtils.PAUSE:
        startButton.setImageResource(R.drawable.start);
        break;
      default:
        break;
      }
      
    }
    
  }
}




Java Source Code List

com.qinxiandiqi.adapter.MusicAdapter.java
com.qinxiandiqi.adapter.VideoAdapter.java
com.qinxiandiqi.bean.MediaFile.java
com.qinxiandiqi.bean.MusicFile.java
com.qinxiandiqi.bean.VideoFile.java
com.qinxiandiqi.nplayer.MainActivity.java
com.qinxiandiqi.nplayer.MusicActivity.java
com.qinxiandiqi.nplayer.SearchActivity.java
com.qinxiandiqi.nplayer.VideoActivity.java
com.qinxiandiqi.service.MusicService.java
com.qinxiandiqi.utils.AdapterUtils.java
com.qinxiandiqi.utils.CodeUtils.java
com.qinxiandiqi.utils.FileUtils.java
com.qinxiandiqi.utils.MediaUtils.java
com.qinxiandiqi.utils.PlayingUtils.java
com.qinxiandiqi.utils.PreferenceUtils.java
com.qinxiandiqi.utils.XMLUtils.java