Back to project page NPlayer.
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.
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; } } } }