Search in sources :

Example 1 with Track

use of guichaguri.trackplayer.logic.track.Track in project react-native-track-player by react-native-kit.

the class MediaManager method onPlay.

public void onPlay() {
    Log.d(Utils.TAG, "onPlay: The service is now on foreground, audio focus, wake and wifi locks have been acquired");
    MediaNotification notification = metadata.getNotification();
    // Set the service as foreground, updating and showing the notification
    service.startForeground(MediaNotification.NOTIFICATION_ID, notification.build());
    notification.setShowing(true);
    // Activate the session
    metadata.setEnabled(true);
    if (!playback.isRemote()) {
        // Enable the audio focus so the device knows we are playing music
        focus.enable();
        // Acquire the wake lock so the device doesn't sleeps stopping the music
        if (!wakeLock.isHeld())
            wakeLock.acquire();
        Track currentTrack = playback.getCurrentTrack();
        if (currentTrack != null && !currentTrack.urlLocal) {
            // Acquire wifi lock when the track needs network
            if (!wifiLock.isHeld())
                wifiLock.acquire();
        }
    }
    if (!serviceStarted) {
        Log.d(Utils.TAG, "Marking the service as started, as there is now playback");
        service.startService(new Intent(service, PlayerService.class));
        serviceStarted = true;
    }
}
Also used : PlayerService(guichaguri.trackplayer.logic.services.PlayerService) MediaNotification(guichaguri.trackplayer.metadata.components.MediaNotification) Intent(android.content.Intent) Track(guichaguri.trackplayer.logic.track.Track)

Example 2 with Track

use of guichaguri.trackplayer.logic.track.Track in project react-native-track-player by react-native-kit.

the class MediaWrapper method getTrack.

public void getTrack(final String id, final Promise callback) {
    Playback pb = manager.getPlayback();
    if (checkPlayback(pb, callback))
        return;
    for (Track track : pb.getQueue()) {
        if (track.id.equals(id)) {
            Utils.resolveCallback(callback, Arguments.fromBundle(track.toBundle()));
            return;
        }
    }
    Utils.rejectCallback(callback, "track", "No track found");
}
Also used : Playback(guichaguri.trackplayer.player.Playback) Track(guichaguri.trackplayer.logic.track.Track)

Example 3 with Track

use of guichaguri.trackplayer.logic.track.Track in project react-native-track-player by react-native-kit.

the class Playback method onEnd.

protected void onEnd() {
    Track previous = getCurrentTrack();
    long position = getPosition();
    manager.onEnd(previous, position);
}
Also used : Track(guichaguri.trackplayer.logic.track.Track)

Example 4 with Track

use of guichaguri.trackplayer.logic.track.Track in project react-native-track-player by react-native-kit.

the class Playback method reset.

public void reset() {
    Track prev = getCurrentTrack();
    long pos = getPosition();
    queue.clear();
    manager.onQueueUpdate();
    currentTrack = -1;
    manager.onTrackUpdate(prev, pos, null, true);
}
Also used : Track(guichaguri.trackplayer.logic.track.Track)

Example 5 with Track

use of guichaguri.trackplayer.logic.track.Track in project react-native-track-player by react-native-kit.

the class Playback method remove.

public void remove(List<String> ids, Promise callback) {
    ListIterator<Track> i = queue.listIterator();
    int currTrack = currentTrack;
    while (i.hasNext()) {
        int index = i.nextIndex();
        Track track = i.next();
        for (String id : ids) {
            if (track.id.equals(id)) {
                i.remove();
                if (currTrack == index) {
                    currTrack = i.nextIndex();
                }
                break;
            }
        }
    }
    if (currTrack != currentTrack) {
        updateCurrentTrack(currTrack, null);
    }
    Utils.resolveCallback(callback);
    manager.onQueueUpdate();
}
Also used : Track(guichaguri.trackplayer.logic.track.Track)

Aggregations

Track (guichaguri.trackplayer.logic.track.Track)11 Playback (guichaguri.trackplayer.player.Playback)3 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 QueueItem (android.support.v4.media.session.MediaSessionCompat.QueueItem)1 PlayerService (guichaguri.trackplayer.logic.services.PlayerService)1 MediaNotification (guichaguri.trackplayer.metadata.components.MediaNotification)1