Android Open Source - Media-Pack Playback Toolbar






From Project

Back to project page Media-Pack.

License

The source code is released under:

Apache License

If you think the Android project Media-Pack 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

//
//               INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//        Copyright (c) 2013-2014 Intel Corporation. All Rights Reserved.
///*  w  w w . j a v  a2 s .  co  m*/

package com.intel.inde.mp.samples.controls;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import com.intel.inde.mp.samples.R;

public class PlaybackToolbar extends LinearLayout implements View.OnClickListener, SeekBar.OnSeekBarChangeListener
{
  //////////////////////////////////////////////////////////////////////
  // Callback Interface
  //////////////////////////////////////////////////////////////////////
  
  public interface OnCommandListener
  {
    void onPlaybackToolbarPlay();
    void onPlaybackToolbarPause();

    void onPlaybackToolbarPositionChanged(long value);
  }
  
  //////////////////////////////////////////////////////////////////////
  // Controls
  //////////////////////////////////////////////////////////////////////
  
  private ImageButton mPlayButton;
  private ImageButton mPauseButton;
  private TextView mPlayTimeText;
  private SeekBar mPlayProgress;

  //////////////////////////////////////////////////////////////////////
  // Variables
  //////////////////////////////////////////////////////////////////////
  
  private long mDuration = 0;
  private long mPosition = 0;

  private OnCommandListener mCallback;
  
  public PlaybackToolbar(Context context)
  {
    super(context);
  }
  
  public PlaybackToolbar(Context context, AttributeSet attrs) 
  {
        super(context, attrs);
 
    LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        li.inflate(R.layout.playback_toolbar, this, true);
        
        bindControls();
        
        setDuration(0);
        setPosition(0);
    }
  
  private void bindControls()
  {
    mPlayButton = (ImageButton) findViewById(R.id.playButton);    
    mPlayButton.setOnClickListener(this);
    
    mPauseButton = (ImageButton) findViewById(R.id.pauseButton);    
    mPauseButton.setOnClickListener(this);

    mPlayTimeText = (TextView)findViewById(R.id.playTimeText);
    
    mPlayProgress = (SeekBar)findViewById(R.id.playProgress);
    mPlayProgress.setOnSeekBarChangeListener(this);
  }
  
  //////////////////////////////////////////////////////////////////////
  // Interface
  //////////////////////////////////////////////////////////////////////
  
  public void setOnCommandListener(OnCommandListener listener)
  {
    mCallback = listener;
  }
  
  public void setPlayState()
  {
    mPlayButton.setVisibility(View.INVISIBLE);
    mPauseButton.setVisibility(View.VISIBLE);
  }
  
  public void setPauseState()
  {
    mPlayButton.setVisibility(View.VISIBLE);
    mPauseButton.setVisibility(View.INVISIBLE);
  }
  
  public void setPosition(long position)
  {
    mPosition = position;
    
    updateControls();
  }
  
  public void setDuration(long duration)
  {
    mDuration = duration;
    
    if(mDuration > 0)
    {
      mPlayProgress.setMax(100);
    }
    
    updateControls();
  }
  
  public void showToolbar(Boolean show)
  {
    TranslateAnimation anim = null;  
    
    if(show)
        {
      setVisibility(View.VISIBLE);
      anim = new TranslateAnimation(0.0f, 0.0f, this.getHeight(), 0.0f);
        }
    else
    {
      anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, this.getHeight());
      
      anim.setAnimationListener(toolbarAnimationListener);
    }
    
        anim.setDuration(300);
        anim.setInterpolator(new AccelerateInterpolator(1.0f));
        this.startAnimation(anim);
  }
  
  public void toggleToolbar()
  {
    showToolbar(getVisibility() != View.VISIBLE);
  }
  
  //////////////////////////////////////////////////////////////////////
  // View.OnClickListener Implementation
  //////////////////////////////////////////////////////////////////////
  
  public void onClick(View v) 
  {
    switch (v.getId()) 
    {
      case R.id.playButton:
      {
        onMediaPlay();
      }
      break;
      
      case R.id.pauseButton: 
      {
        onMediaPause();
      }
      break;
    }
  }
  
  //////////////////////////////////////////////////////////////////////
  // SeekBar.OnSeekBarChangeListener Implementation
  //////////////////////////////////////////////////////////////////////
  
  @Override
  public void onProgressChanged(SeekBar view, int value, boolean user)
  {    
    if(user == false)
    {
      return;
    }
    
    long newPosition = (long)Math.round((mDuration * value) / 100f);
    
    mCallback.onPlaybackToolbarPositionChanged(newPosition);
  }

  @Override
  public void onStartTrackingTouch(SeekBar seekBar)
  {    
  }

  @Override
  public void onStopTrackingTouch(SeekBar seekBar)
  {
  }
  
  //////////////////////////////////////////////////////////////////////
  // Click Handlers Implementation
  //////////////////////////////////////////////////////////////////////
  
  private void onMediaPlay()
  {
    mCallback.onPlaybackToolbarPlay();
  }
  
  private void onMediaPause()
  {
    mCallback.onPlaybackToolbarPause();
  }

  //////////////////////////////////////////////////////////////////////
  // Show\Hide Animation
  //////////////////////////////////////////////////////////////////////
  
  Animation.AnimationListener toolbarAnimationListener = new Animation.AnimationListener() 
  {
      public void onAnimationEnd(Animation animation) 
      {
        setVisibility(View.GONE);
      }

      @Override
      public void onAnimationRepeat(Animation animation) 
      {
      }

      @Override
      public void onAnimationStart(Animation animation) 
      {
      }
  };
  
  //////////////////////////////////////////////////////////////////////
  // Update UI
  //////////////////////////////////////////////////////////////////////
  
  private void updateControls()
  {
        long duration = mPosition / 1000;

        long h = duration / 3600;
        long m = (duration - h * 3600) / 60;
        long s = duration - (h * 3600 + m * 60);

        String time;

        if (h == 0)
        {
            time = asTwoDigit(m) + ":" + asTwoDigit(s);
        }
        else
        {
            time = asTwoDigit(h) + ":" + asTwoDigit(m) + ":" + asTwoDigit(s);
        }
      
      mPlayTimeText.setText(time);
      
      int playProgress = 0;
      
      if(mDuration != 0)
      {
        playProgress = (int)((mPosition * 100) / mDuration);
      }      
      
      mPlayProgress.setProgress(playProgress);
  }

    private String asTwoDigit(long digit)
    {
        String value = "";

        if (digit < 10)
        {
            value = "0";
        }

        value += String.valueOf(digit);

        return value;
    }

}




Java Source Code List

com.intel.inde.mp.android.graphics.EglUtil.java
com.intel.inde.mp.android.graphics.FrameBuffer.java
com.intel.inde.mp.android.graphics.FullFrameTexture.java
com.intel.inde.mp.android.graphics.ShaderProgram.java
com.intel.inde.mp.android.graphics.VideoEffect.java
com.intel.inde.mp.effects.AudioEffect.java
com.intel.inde.mp.effects.AudioReader.java
com.intel.inde.mp.effects.GrayScaleEffect.java
com.intel.inde.mp.effects.InverseEffect.java
com.intel.inde.mp.effects.JpegSubstituteEffect.java
com.intel.inde.mp.effects.OverlayEffect.java
com.intel.inde.mp.effects.RotateEffect.java
com.intel.inde.mp.effects.SepiaEffect.java
com.intel.inde.mp.effects.SubstituteAudioEffect.java
com.intel.inde.mp.effects.TextOverlayEffect.java
com.intel.inde.mp.samples.ActivityWithTimeline.java
com.intel.inde.mp.samples.CameraCapturerActivity.java
com.intel.inde.mp.samples.CameraStreamerActivity.java
com.intel.inde.mp.samples.ComposerAudioEffectActivity.java
com.intel.inde.mp.samples.ComposerAudioEffectCoreActivity.java
com.intel.inde.mp.samples.ComposerCutActivity.java
com.intel.inde.mp.samples.ComposerCutCoreActivity.java
com.intel.inde.mp.samples.ComposerJoinActivity.java
com.intel.inde.mp.samples.ComposerJoinCoreActivity.java
com.intel.inde.mp.samples.ComposerMediaFileInfoActivity.java
com.intel.inde.mp.samples.ComposerMediaFileInfoCoreActivity.java
com.intel.inde.mp.samples.ComposerTranscodeActivity.java
com.intel.inde.mp.samples.ComposerTranscodeCoreActivity.java
com.intel.inde.mp.samples.ComposerVideoEffectActivity.java
com.intel.inde.mp.samples.ComposerVideoEffectCoreActivity.java
com.intel.inde.mp.samples.DemoListAdapter.java
com.intel.inde.mp.samples.DemoListItem.java
com.intel.inde.mp.samples.ExpandableSamplesListAdapter.java
com.intel.inde.mp.samples.FPSCounter.java
com.intel.inde.mp.samples.Format.java
com.intel.inde.mp.samples.GameCapturing.java
com.intel.inde.mp.samples.GameRenderer.java
com.intel.inde.mp.samples.GameStreaming.java
com.intel.inde.mp.samples.MediaStreamerActivity.java
com.intel.inde.mp.samples.MediaStreamerCoreActivity.java
com.intel.inde.mp.samples.RecognitionActivity.java
com.intel.inde.mp.samples.SamplesMainActivity.java
com.intel.inde.mp.samples.VideoCapture.java
com.intel.inde.mp.samples.VideoPlayerActivity.java
com.intel.inde.mp.samples.VideoStreamPlayerActivity.java
com.intel.inde.mp.samples.controls.CameraCaptureSettingsPopup.java
com.intel.inde.mp.samples.controls.GameGLSurfaceView.java
com.intel.inde.mp.samples.controls.PlaybackToolbar.java
com.intel.inde.mp.samples.controls.PopupMessage.java
com.intel.inde.mp.samples.controls.Popup.java
com.intel.inde.mp.samples.controls.RangeSelector.java
com.intel.inde.mp.samples.controls.TimelineItem.java
com.intel.inde.mp.samples.controls.TranscodeSurfaceView.java
com.intel.inde.mp.samples.controls.VideoPlayer.java