Android Open Source - audioplayer Mini Player View Controller






From Project

Back to project page audioplayer.

License

The source code is released under:

GNU General Public License

If you think the Android project audioplayer 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 fr.julien_dumortier.simplemusicplayer.playerview;
/* w w  w .  j av a2  s .co  m*/
import android.graphics.drawable.Drawable;
import android.support.v4.widget.DrawerLayout;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import fr.julien_dumortier.simplemusicplayer.R;
import fr.julien_dumortier.simplemusicplayer.MainActivity;
import fr.julien_dumortier.simplemusicplayer.item.Track;
import fr.julien_dumortier.simplemusicplayer.item.Item.IOnPictureReady;
import fr.julien_dumortier.simplemusicplayer.service.playlist.IMediaPlayerController;
import fr.julien_dumortier.simplemusicplayer.service.playlist.MusicMediaPlayer;
import fr.julien_dumortier.simplemusicplayer.thememanager.DisplayManager2;

public class MiniPlayerViewController implements IPlayerViewController, IOnPictureReady {

  private MainActivity mContext;
  private TextView mTrackName;
  private TextView mArtistName;
  private ImageView mPlay, mTrackImage;
  private SeekBar mProgression;
  private boolean isPlayingMode, isShowingPlayer;
  private IMediaPlayerController mMediaPlayerController;
  private View mPlayerContainer;
  
  public MiniPlayerViewController(MainActivity act, View v, SeekBar progress, 
      IMediaPlayerController mediaPlayerController) {
    mContext = act;
    mPlayerContainer = v;
    isShowingPlayer = false;
    mTrackImage = ((ImageView)v.findViewById(R.id.musique_image));
        mTrackName = ((TextView)v.findViewById(R.id.mini_track_name));
        mArtistName = ((TextView)v.findViewById(R.id.mini_artist_name));
        mPlay = ((ImageView)v.findViewById(R.id.button_play));
    mPlay.setOnTouchListener(new OnTouchListener() {
      public boolean onTouch(View v, MotionEvent event) {
        if(MotionEvent.ACTION_DOWN == event.getAction()) {
          if(isPlayingMode)
            ((ImageView)v).setImageDrawable(mContext.getResources().getDrawable(R.drawable.pause_click));
          else
            ((ImageView)v).setImageDrawable(mContext.getResources().getDrawable(R.drawable.play_click));  
        }
        if(MotionEvent.ACTION_UP == event.getAction()) {
          if(isPlayingMode)
            pause();
          else
            play();    
        }
        return true;
      }
    });        
    mProgression = progress;
    updateThumbStyle();
    /*mProgression.setProgressDrawable(act.getResources().getDrawable(R.drawable.seekbar_color));/*
    LayerDrawable ld = (LayerDrawable) mProgression.getProgressDrawable();
    ClipDrawable d1 = (ClipDrawable) ld.findDrawableByLayerId(R.id.progressshape);
    d1.setColorFilter(Color.parseColor("#202a36"), android.graphics.PorterDuff.Mode.SRC_IN);*/
    mProgression.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
      public void onStopTrackingTouch(SeekBar arg0) {
        mMediaPlayerController.seekToPercent((mProgression.getProgress()*100)/mProgression.getMax());
      }
      
      public void onStartTrackingTouch(SeekBar arg0) {}      
      public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {}
    });
    mMediaPlayerController = mediaPlayerController;
  }
  
  public void updateThumbStyle() {
    mProgression.setProgressDrawable(DisplayManager2.getProgressStyleDrawable(mContext));
    mProgression.setThumb(DisplayManager2.getThumbStyleDrawable(mContext));
  }
  
  public void setPercentTime(int percentPlayed) {
    mProgression.setProgress((percentPlayed*mProgression.getMax())/100);
  }

  public void setTimePlayed(final long timePlayed, final long restTimePlayed) {
    
  }

  public void initView(final MusicMediaPlayer mediaPlayer) {
    mContext.runOnUiThread(new Runnable(){public void run(){
      Track track = mediaPlayer.getCurrentTrack();
      if(track!=null) {
        if(track.isDefaultPicture)
          track.initPicture();
        mTrackName.setText(track.getTrackName());
        mArtistName.setText(track.getArtistName());
        mTrackImage.setImageDrawable(track.getPicture());
        mProgression.setProgress((mediaPlayer.getPercentPlayed()*mProgression.getMax())/100); 
        if(mediaPlayer.isPlaying()) 
          mPlay.setImageDrawable(mContext.getResources().getDrawable(R.drawable.pause));
        else
          mPlay.setImageDrawable(mContext.getResources().getDrawable(R.drawable.play));
        isPlayingMode = mediaPlayer.isPlaying();
        showPlayer();
      } else {
        dismissPlayer();
      }
    }});
  }

  public void play() {
    if(!isPlayingMode && mMediaPlayerController.getCurrentTrack()!=null)
    mContext.runOnUiThread(new Runnable() {
      public void run() {
        isPlayingMode = true;
        mProgression.setEnabled(true);
        mMediaPlayerController.resume();
        mPlay.setImageDrawable(mContext.getResources().getDrawable(R.drawable.pause));
      }
    });
  }

  
  public void pause() {
    if(isPlayingMode)
    mContext.runOnUiThread(new Runnable() {
      public void run() {
        isPlayingMode = false;
        mMediaPlayerController.pause();
        mPlay.setImageDrawable(mContext.getResources().getDrawable(R.drawable.play));
      }
    });
  }

  public void setRepeat(int repeatMode) {}

  public void setRandom(boolean b) {}

  public void stop() {
    pause();
    clearView();
  }

  public void clearView() {
    mContext.runOnUiThread(new Runnable(){public void run(){
      mTrackName.setText("");
      mArtistName.setText("");
      mTrackImage.setImageDrawable(null);
      dismissPlayer();
    }});
  }

  private void showPlayer() {
    if(!isShowingPlayer) {
      int h = mPlayerContainer.getHeight();
      if(h<10)
        h=200;
      Animation anim = new TranslateAnimation(0, 0, h, 0);
      anim.setDuration(600);
      anim.setInterpolator(new DecelerateInterpolator());
      anim.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation animation) {
          mPlayerContainer.setVisibility(View.VISIBLE);
        }      
        public void onAnimationRepeat(Animation animation) {}      
        public void onAnimationEnd(Animation animation) {
          //mProgression.setVisibility(View.VISIBLE);
          mProgression.setY(mPlayerContainer.getY()-mPlayerContainer.getHeight()-30);
          mProgression.setLayoutParams(new DrawerLayout.LayoutParams(DrawerLayout.LayoutParams.FILL_PARENT, 15));
          mContext.updateGridViewLayoutParams(false);
        }
      });
      anim.setFillAfter(true);
      mPlayerContainer.clearAnimation();
      mPlayerContainer.startAnimation(anim);
    }
    isShowingPlayer = true;
  }
  
  private void dismissPlayer() {
    if(isShowingPlayer) {
      int h = mPlayerContainer.getHeight();
      if(h<10)
        h=200;
      Animation anim = new TranslateAnimation(0, 0, 0, h);
      anim.setDuration(600);
      anim.setInterpolator(new DecelerateInterpolator());
      anim.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation animation) {
          mProgression.setVisibility(View.GONE);
        }      
        public void onAnimationRepeat(Animation animation) {}      
        public void onAnimationEnd(Animation animation) {
          mPlayerContainer.setVisibility(View.GONE);
          mContext.updateGridViewLayoutParams(true);
        }
      });
      anim.setFillAfter(true);
      mPlayerContainer.clearAnimation();
      mPlayerContainer.startAnimation(anim);
    }
    isShowingPlayer = false;
  }

  public void onPictureReady(final Drawable picture, int posFlag) {
    mContext.runOnUiThread(new Runnable() {
      public void run() {
        mTrackImage.setImageDrawable(picture);
      }
    });
  }
}




Java Source Code List

fr.julien_dumortier.simplemusicplayer.DevInfo.java
fr.julien_dumortier.simplemusicplayer.DrawerListAdapter.java
fr.julien_dumortier.simplemusicplayer.IMusicMediaControllerGetter.java
fr.julien_dumortier.simplemusicplayer.MainActivity.java
fr.julien_dumortier.simplemusicplayer.browsemanager.BrowseCover.java
fr.julien_dumortier.simplemusicplayer.browsemanager.BrowseManager.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.CoverAlbumEditor.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.CoverAlbumGetter.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.PromptCovers.java
fr.julien_dumortier.simplemusicplayer.equalizer.EqualizerActivity.java
fr.julien_dumortier.simplemusicplayer.equalizer.EqualizerConfigurationDataBase.java
fr.julien_dumortier.simplemusicplayer.equalizer.VerticalSeekBar.java
fr.julien_dumortier.simplemusicplayer.equalizer.preset.Preset.java
fr.julien_dumortier.simplemusicplayer.item.Album.java
fr.julien_dumortier.simplemusicplayer.item.Artist.java
fr.julien_dumortier.simplemusicplayer.item.Genre.java
fr.julien_dumortier.simplemusicplayer.item.Item.java
fr.julien_dumortier.simplemusicplayer.item.Playlist.java
fr.julien_dumortier.simplemusicplayer.item.Track.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.AlbumAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ArtistAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.CurrentPlayAnimationManager.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.GenreAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ItemAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ItemClicManager.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.OrganisableTrackAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.PlayListAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.TrackAdapter.java
fr.julien_dumortier.simplemusicplayer.notifynews.NotifyNews.java
fr.julien_dumortier.simplemusicplayer.playerview.FullScreenPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.IPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.MiniPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.TimeFormater.java
fr.julien_dumortier.simplemusicplayer.playlistview.MultiSelectManager.java
fr.julien_dumortier.simplemusicplayer.playlistview.PlayListManagerActivity.java
fr.julien_dumortier.simplemusicplayer.playlistview.SaveManagerView.java
fr.julien_dumortier.simplemusicplayer.playlistview.SavedPlaylistManager.java
fr.julien_dumortier.simplemusicplayer.service.BackgroundBinder.java
fr.julien_dumortier.simplemusicplayer.service.MusicPlayerService.java
fr.julien_dumortier.simplemusicplayer.service.bluetoohactionmanager.BluetoothReceiver.java
fr.julien_dumortier.simplemusicplayer.service.notificationplayer.NotificationManagerService.java
fr.julien_dumortier.simplemusicplayer.service.notificationplayer.NotificationPlayer.java
fr.julien_dumortier.simplemusicplayer.service.phonestatemanager.PhoneCallStateManager.java
fr.julien_dumortier.simplemusicplayer.service.playlist.EndOfPlayListException.java
fr.julien_dumortier.simplemusicplayer.service.playlist.IMediaPlayerController.java
fr.julien_dumortier.simplemusicplayer.service.playlist.MusicMediaPlayer.java
fr.julien_dumortier.simplemusicplayer.service.playlist.PlayListManager.java
fr.julien_dumortier.simplemusicplayer.thememanager.ColorPreferences.java
fr.julien_dumortier.simplemusicplayer.thememanager.DisplayManager2.java
fr.julien_dumortier.simplemusicplayer.thememanager.ManageDisplayView.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptActionByType.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptActionPlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmAddInNew.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmDeletePlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmExit.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmReplacePlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptDefineCoverAlbum.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptGetTextName.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptMoveTrack.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptPlaylistName.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptShowText.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptSuppressConfirm.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerApplication.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerWidgetProvider.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerWidgetViewController.java
fr.julien_dumortier.simplemusicplayer.widget.WidgetView.java