add custom event listener for playback controls
This commit is contained in:
parent
225e3562f4
commit
fcd88b7859
2 changed files with 144 additions and 2 deletions
|
|
@ -6,13 +6,13 @@ import android.content.Context;
|
|||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.dkanada.gramophone.helper.EventListener;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||
import com.dkanada.gramophone.shortcuts.DynamicShortcutManager;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.AndroidDevice;
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
import org.jellyfin.apiclient.interaction.ApiEventListener;
|
||||
import org.jellyfin.apiclient.interaction.VolleyHttpClient;
|
||||
import org.jellyfin.apiclient.interaction.device.IDevice;
|
||||
import org.jellyfin.apiclient.interaction.http.IAsyncHttpClient;
|
||||
|
|
@ -54,7 +54,7 @@ public class App extends Application {
|
|||
ILogger logger = new AndroidLogger(context.getClass().getName());
|
||||
IAsyncHttpClient httpClient = new VolleyHttpClient(logger, context);
|
||||
IDevice device = new AndroidDevice(deviceId, deviceName);
|
||||
ApiEventListener eventListener = new ApiEventListener();
|
||||
EventListener eventListener = new EventListener();
|
||||
|
||||
return new ApiClient(httpClient, logger, server, appName, appVersion, device, eventListener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,142 @@
|
|||
package com.dkanada.gramophone.helper;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
import org.jellyfin.apiclient.interaction.ApiEventListener;
|
||||
import org.jellyfin.apiclient.model.apiclient.RemoteLogoutReason;
|
||||
import org.jellyfin.apiclient.model.apiclient.SessionUpdatesEventArgs;
|
||||
import org.jellyfin.apiclient.model.dto.UserDto;
|
||||
import org.jellyfin.apiclient.model.entities.LibraryUpdateInfo;
|
||||
import org.jellyfin.apiclient.model.session.BrowseRequest;
|
||||
import org.jellyfin.apiclient.model.session.GeneralCommand;
|
||||
import org.jellyfin.apiclient.model.session.MessageCommand;
|
||||
import org.jellyfin.apiclient.model.session.PlayRequest;
|
||||
import org.jellyfin.apiclient.model.session.PlaystateRequest;
|
||||
import org.jellyfin.apiclient.model.session.SessionInfoDto;
|
||||
import org.jellyfin.apiclient.model.session.UserDataChangeInfo;
|
||||
|
||||
public class EventListener extends ApiEventListener {
|
||||
public static final String TAG = EventListener.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public void onRemoteLoggedOut(ApiClient client, RemoteLogoutReason reason) {
|
||||
Log.i(TAG, "onRemoteLoggedOut");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserUpdated(ApiClient client, UserDto userDto) {
|
||||
Log.i(TAG, "onUserUpdated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLibraryChanged(ApiClient client, LibraryUpdateInfo info) {
|
||||
Log.i(TAG, "onLibraryChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserConfigurationUpdated(ApiClient client, UserDto userDto) {
|
||||
Log.i(TAG, "onUserConfigurationUpdated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBrowseCommand(ApiClient client, BrowseRequest command) {
|
||||
Log.i(TAG, "onBrowseCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayCommand(ApiClient client, PlayRequest command) {
|
||||
Log.i(TAG, "onPlayCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaystateCommand(ApiClient client, PlaystateRequest command) {
|
||||
Log.i(TAG, "onPlayStateCommand");
|
||||
|
||||
switch (command.getCommand()) {
|
||||
case PlayPause:
|
||||
if (MusicPlayerRemote.isPlaying()) {
|
||||
MusicPlayerRemote.pauseSong();
|
||||
} else {
|
||||
MusicPlayerRemote.resumePlaying();
|
||||
}
|
||||
break;
|
||||
case Pause:
|
||||
MusicPlayerRemote.pauseSong();
|
||||
break;
|
||||
case Unpause:
|
||||
MusicPlayerRemote.resumePlaying();
|
||||
break;
|
||||
case NextTrack:
|
||||
MusicPlayerRemote.playNextSong();
|
||||
case PreviousTrack:
|
||||
MusicPlayerRemote.playPreviousSong();
|
||||
break;
|
||||
case Rewind:
|
||||
case FastForward:
|
||||
break;
|
||||
case Seek:
|
||||
long position = command.getSeekPositionTicks() / 10000;
|
||||
MusicPlayerRemote.seekTo((int) position);
|
||||
break;
|
||||
case Stop:
|
||||
MusicPlayerRemote.pauseSong();
|
||||
MusicPlayerRemote.clearQueue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageCommand(ApiClient client, MessageCommand command) {
|
||||
Log.i(TAG, "onMessageCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeneralCommand(ApiClient client, GeneralCommand command) {
|
||||
Log.i(TAG, "onGeneralCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendStringCommand(ApiClient client, String value) {
|
||||
Log.i(TAG, "onSendStringCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetVolumeCommand(ApiClient client, int value) {
|
||||
Log.i(TAG, "onSetVolumeCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetAudioStreamIndexCommand(ApiClient client, int value) {
|
||||
Log.i(TAG, "onSetAudioStreamIndexCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetSubtitleStreamIndexCommand(ApiClient client, int value) {
|
||||
Log.i(TAG, "onSetSubtitleStreamIndexCommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserDataChanged(ApiClient client, UserDataChangeInfo info) {
|
||||
Log.i(TAG, "onUserDataChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionsUpdated(ApiClient client, SessionUpdatesEventArgs args) {
|
||||
Log.i(TAG, "onSessionsUpdated");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStart(ApiClient client, SessionInfoDto info) {
|
||||
Log.i(TAG, "onPlaybackStart");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStopped(ApiClient client, SessionInfoDto info) {
|
||||
Log.i(TAG, "onPlaybackStopped");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionEnded(ApiClient client, SessionInfoDto info) {
|
||||
Log.i(TAG, "onSessionEnded");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue