GithubHelp home page GithubHelp logo

musicbar's Introduction

MusicBar Logo

MusicBar Download Android Arsenal

Setup

dependencies {
      implementation 'com.oze.music:MusicBar:1.0.5'
}

Usage

Function Description
setAnimationChangeListener(OnMusicBarAnimationChangeListener listener) animation listener
setProgressChangeListener(OnMusicBarProgressChangeListener listener) progress listener
removeAllListener() remove Progress and Animation listener
loadFrom(InputStream stream, int duration) take the music file InputStream with music duration in millisecond
loadFrom(String pathname, int duration) take the music file path with music duration in millisecond
show() start show animation
hide() start hide animation
startAutoProgress(float playbackSpeed) start auto play animation should be called after loadFrom() and media player finished prepare if startAutoProgress() called before loadFrom() it will throw exception because duration is 0. every time loadFrom() call you will need to recall startAutoProgress() playbackSpeed playback speed from media player default value 1.0F for MediaPlayer and ExoPlayer
stopAutoProgress() stop auto progress animation
isHide() return true if hide
isShow() return true if show
isAutoProgress() return true if auto progress
setProgress(int position) move to specified position (in milisecand)
getPosition() return current progress position
setSpaceBetweenBar(int spaceBetweenBar) change distance between bars (in px) default 2 Recommend to make spaceBetweenBar equal barWidth if you use FixedMusicBar
setBarWidth(float barWidth) change bar width (in px) default 2 for FixedMusicBar and 3 for ScrollableMusicBar Recommend to make barWidth equal spaceBetweenBar if you use FixedMusicBar
setLoadedBarPrimeColor(int color) change top progressed bar color default #fb4c01
setBackgroundBarPrimeColor(int color) change top unprogressed bar color default #dfd6d6

Only in ScrollableMusicBar

Function Description
setDivided(boolean divided) Set if music bar divided or not default false
setDividerSize(float size) Set divider size in px default 2 use when view is divided
setLoadedBarSecondaryColor(int color) change bottom progressed bar color default #eca277 use when view is divided
setBackgroundBarSecondaryColor(int color) change bottom unprogressed bar color default #c4bbbb use when view is divided

XML

for ScrollableMusicBar

ScrollableMusicBar

   <com.oze.music.musicbar.ScrollableMusicBar
        android:id="@+id/ScrollableMusicBar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@android:color/white"
        android:padding="8dp"
        app:divided="true"                               // to divide each bar default false
        app:dividerSize="2"                              // divide sice in px default 2
        app:barWidth="3"                                 // bar width default 3
        app:spaceBetweenBar="2"                          // distance between each bar default 2
        app:backgroundBarPrimeColor="#dfd6d6"
        app:backgroundBarSecondaryColor="#c4bbbb"
        app:LoadedBarPrimeColor="#fb4c01"
        app:LoadedBarSecondaryColor="#eca277"/>

OR FixedMusicBar

FixedMusicBar

    <com.oze.music.musicbar.FixedMusicBar
        android:id="@+id/FixedMusicBar"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:padding="8dp"
        android:background="@android:color/white"
        app:barWidth="2"                           // bar width default 2
        app:spaceBetweenBar="2"                    // distance between each bar default 2
        app:backgroundBarPrimeColor="#dfd6d6"
        app:LoadedBarPrimeColor="#fb4c01"/>

Java

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        ScrollableMusicBar musicBar = findViewById(R.id.ScrollableMusicBar);
        //or  
        FixedMusicBar musicBar = findViewById(R.id.FixedMusicBar);
        
        //add animation listener
        musicBar.setAnimationChangeListener(mOnMusicBarAnimationChangeListener);
        
        //add progress listener
        musicBar.setProgressChangeListener(mOnMusicBarProgressChangeListener);
        
         // String path = the music file path
        // int duration = the music file duration time in millisecond [mediaPlayer.getDuration()]
        musicBar.loadFrom(path,duration)
        //or use inputstream 
        musicBar.loadFrom(getResources().openRawResource(R.raw.music),duration());
        
        //change progress 
        musicBar.setProgress(50)
        
        //start show animation
        musicBar.show()
        
        //start hide animation
        musicBar.hide()
        
        //change bar width
        musicBar.setBarWidth(2);
        
        //change Space Between Bars
        musicBar.setSpaceBetweenBar(2); //Recommend to make spaceBetweenBar equal barWidth if you use FixedMusicBar
       
        // Set if music bar divided or not default value false.
        musicBar.setDivided(true);
        
        //Set divider size in px default value 2
        musicBar.setDividerSize();
        
        // for changing color scheme
        musicBar.setBackgroundBarPrimeColor(getResources().getColor(R.color.BackgroundBarPrimeColor);
        musicBar.setBackgroundBarSecondaryColor(getResources().getColor(R.color.BackgroundBarSecondaryColor);
        musicBar.setLoadedBarPrimeColor(getResources().getColor(R.color.LoadedBarPrimeColor);
        musicBar.setLoadedBarSecondaryColor(getResources().getColor(R.color.LoadedBarSecondaryColor);


        mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                musicBar.startAutoProgress(1.0f);
            }
        });
        
        //stop auto progress animation
        musicBar.stopAutoProgress();
        
    }

AnimationListener

MusicBar.OnMusicBarAnimationChangeListener mOnMusicBarAnimationChangeListener = new MusicBar.OnMusicBarAnimationChangeListener() {
        @Override
        public void onHideAnimationStart() {
            Log.i(TAG, "onHideAnimationStart");
        }

        @Override
        public void onHideAnimationEnd() {
            Log.i(TAG, "onHideAnimationEnd");
        }

        @Override
        public void onShowAnimationStart() {
            Log.i(TAG, "onShowAnimationStart");

        }

        @Override
        public void onShowAnimationEnd() {
            Log.i(TAG, "onShowAnimationEnd");
        }
    };

ProgressListener

 MusicBar.OnMusicBarProgressChangeListener mOnMusicBarProgressChangeListener = new MusicBar.OnMusicBarProgressChangeListener() {
        @Override
        public void onProgressChanged(MusicBar musicBar, int progress, boolean fromUser) {
            Log.i(TAG, "onProgressChanged");
        }

        @Override
        public void onStartTrackingTouch(MusicBar musicBar) {
         Log.i(TAG, "onStartTrackingTouch");
        }

        @Override
        public void onStopTrackingTouch(MusicBar musicBar) {
            Log.i(TAG, "onStopTrackingTouch");
        }
    };

Animation

animation

musicbar's People

Contributors

emadabdalrahman avatar

Watchers

MAY3AM avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.