MediaPlayerUtil

public class MediaPlayerUtil

Functions

Link copied to clipboard
public final static String createTime(Integer duration)

Converts the milliseconds in a displayable time-format like this --> min:sec

Link copied to clipboard
public final static Integer getAudioSessionId()
Link copied to clipboard
public final static Integer getDuration()
Link copied to clipboard
public final static Integer getPosition()
Link copied to clipboard
public final Boolean isPlaying()
Link copied to clipboard
public final Boolean isStopped()
Link copied to clipboard
public final static Unit pause()

Pauses the mediaPlayer if it currently playing. Returns void if the mediaPlayer isn't set or not currently playing something

Link copied to clipboard
public final static Unit play()

Simply starts the mediaPlayer, but only if the player is set to something and isn't already playing

Link copied to clipboard
public final static Unit playCurrent(Context context)

This methods is mainly used when the user stops the current song and then wants to keep on playing it again. We therefore just look which song is currently assigned to the mediaPlayer and execute the startPlaying method to resume the song

Link copied to clipboard
public final static Unit playNext(Context context)

Plays the next song. If repeat is set to true then it will just keep playing the same song If the song is the last in queue it will play the first song in queue again

Link copied to clipboard
public final static Unit playPrev(Context context)

Plays the previous song in queue If the actual song is the first song it just plays the last song in queue If repeat is set to true, it just plays the same song again

Link copied to clipboard
public final static Unit seekTo(Integer pos)

Sets the mediaPlayer to play at a defined position in the song

Link copied to clipboard
public final static Boolean startPlaying(Context context, Song song)

Uses the mediaPlayer to start playing a song. It then also outputs if this action was successfully or not.

Link copied to clipboard
public final static Unit stop()

Stops and releases the mediaPlayer to avoid errors. This assures a smooth release of memory without leaking or bugs

Link copied to clipboard
public final static Unit togglePlayPause()

Toggles between two modes: paused and playing This is mainly used when the user pauses the player and then wants to resume the song If the mediaPlayer is paused, it starts playing and vice versa

Properties

Link copied to clipboard
private final static Integer audioSessionId

Gets the AudioSessionID of the mediaPlayer

Link copied to clipboard
private final static Integer duration

Gets the duration of the song that is being played right now ( in seconds)

Link copied to clipboard
public final static MediaPlayerUtil INSTANCE
Link copied to clipboard
private final Boolean isPlaying

Checks if the mediaPlayer is playing

Link copied to clipboard
private final Boolean isStopped

Checks if the mediaPlayer is stopped

Link copied to clipboard
private final static Integer position

Gets the position the mediaPlayer is currently at (in seconds)