Skip to content

Paroca72/sc-player

Repository files navigation

sc-PlayerButton

Create a simple button than play a media source.
The basic function are simple a Play/Stop on pressing the button. The button will show the wave-form on playing the media.

IMPORTANT
For showing the wave form require the RECORD_AUDIO permission.
If not, will show a PLAY/STOP simple icon and NOT will show the wave form.


image image

This class inherit from the android View class.
So for example if you would change the background is enough to use the android:background property. For customize the component please read guide below.

Public methods

  • int getDuration()
    Get back the media duration.

  • boolean isPlaying()
    Get the media playing status.

  • void play()
    Start to play the current media

  • void stop()
    Stop to play the current media

  • void setOnEventListener(OnEventListener listener)
    Set the event listener.


Getter and Setter

  • get/setSource -> String value, default null
    Set the current media source (absolute path).

  • get/setColor -> Color value, default #FFFFFF
    Set the current foreground color.

  • get/setFontSize -> float value, default 11dp
    Set the current font size.

  • get/setVolume -> float value, default 0.7
    Set the current media player volume (0..1).

  • get/setPosition -> int value, default 0
    Set the current media player position.


Interfaces

  • OnEventListener
    void onStartPlay(MediaPlayer player);
    Called when the media start to play.
    void onStopPlay();
    Called when the media stop to play.


XML Properties

<declare-styleable name="ScPlayerButton">
    <attr name="source" format="string" />
    <attr name="color" format="color" />
    <attr name="fontSize" format="dimension" />
    <attr name="volume" format="float" />
</declare-styleable>

Usage

via Gradle:
Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Add the dependency

dependencies {
    ...
    compile 'com.github.paroca72:sc-player:1.0.2'
}

Coding

// Get the components
ScPlayerButton player = (ScPlayerButton) this.findViewById(R.id.player);
assert player != null;

// Play the default ringtone
Uri defaultRintoneUri = RingtoneManager
        .getActualDefaultRingtoneUri(this.getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
player.setSource(defaultRintoneUri.toString());


License

 Copyright 2015 Samuele Carassai

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in  writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,  either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.