Fix Widget
This commit is contained in:
parent
d0959ffcb5
commit
e1f4ee15d5
|
@ -127,7 +127,11 @@
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/appwidget_info_4x4"/>
|
android:resource="@xml/appwidget_info_4x4"/>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<receiver android:name=".receiver.MediaButtonIntentReceiver">
|
||||||
|
<intent-filter android:priority="2147483647">
|
||||||
|
<action android:name="android.intent.action.MEDIA_BUTTON"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
<provider
|
<provider
|
||||||
android:name=".provider.SearchSuggestionProvider"
|
android:name=".provider.SearchSuggestionProvider"
|
||||||
android:authorities="org.moire.ultrasonic.provider.SearchSuggestionProvider"/>
|
android:authorities="org.moire.ultrasonic.provider.SearchSuggestionProvider"/>
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
This file is part of Subsonic.
|
|
||||||
|
|
||||||
Subsonic is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Subsonic is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Copyright 2010 (C) Sindre Mehus
|
|
||||||
*/
|
|
||||||
package org.moire.ultrasonic.receiver;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport;
|
|
||||||
import org.moire.ultrasonic.util.Constants;
|
|
||||||
import org.moire.ultrasonic.util.Settings;
|
|
||||||
import org.moire.ultrasonic.util.Util;
|
|
||||||
|
|
||||||
import kotlin.Lazy;
|
|
||||||
|
|
||||||
import static org.koin.java.KoinJavaComponent.inject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Sindre Mehus
|
|
||||||
*/
|
|
||||||
public class MediaButtonIntentReceiver extends BroadcastReceiver
|
|
||||||
{
|
|
||||||
private Lazy<MediaPlayerLifecycleSupport> lifecycleSupport = inject(MediaPlayerLifecycleSupport.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent)
|
|
||||||
{
|
|
||||||
String intentAction = intent.getAction();
|
|
||||||
|
|
||||||
// If media button are turned off and we received a media button, exit
|
|
||||||
if (!Settings.getMediaButtonsEnabled() && Intent.ACTION_MEDIA_BUTTON.equals(intentAction))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Only process media buttons and CMD_PROCESS_KEYCODE, which is received from the widgets
|
|
||||||
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction) &&
|
|
||||||
!Constants.CMD_PROCESS_KEYCODE.equals(intentAction)) return;
|
|
||||||
|
|
||||||
Bundle extras = intent.getExtras();
|
|
||||||
|
|
||||||
if (extras == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Parcelable event = (Parcelable) extras.get(Intent.EXTRA_KEY_EVENT);
|
|
||||||
Timber.i("Got MEDIA_BUTTON key event: %s", event);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Intent serviceIntent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
|
||||||
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
|
|
||||||
lifecycleSupport.getValue().receiveIntent(serviceIntent);
|
|
||||||
|
|
||||||
if (isOrderedBroadcast())
|
|
||||||
{
|
|
||||||
abortBroadcast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception x)
|
|
||||||
{
|
|
||||||
// Ignored.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* MediaButtonIntentReceiver.kt
|
||||||
|
* Copyright (C) 2009-2022 Ultrasonic developers
|
||||||
|
*
|
||||||
|
* Distributed under terms of the GNU GPLv3 license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.receiver
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Parcelable
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport
|
||||||
|
import org.moire.ultrasonic.util.Constants
|
||||||
|
import org.moire.ultrasonic.util.Settings
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used to receive commands from the widget
|
||||||
|
*/
|
||||||
|
class MediaButtonIntentReceiver : BroadcastReceiver(), KoinComponent {
|
||||||
|
private val lifecycleSupport: MediaPlayerLifecycleSupport by inject()
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
val intentAction = intent.action
|
||||||
|
|
||||||
|
// If media button are turned off and we received a media button, exit
|
||||||
|
if (!Settings.mediaButtonsEnabled && Intent.ACTION_MEDIA_BUTTON == intentAction) return
|
||||||
|
|
||||||
|
// Only process media buttons and CMD_PROCESS_KEYCODE, which is received from the widgets
|
||||||
|
if (Intent.ACTION_MEDIA_BUTTON != intentAction &&
|
||||||
|
Constants.CMD_PROCESS_KEYCODE != intentAction
|
||||||
|
) return
|
||||||
|
val extras = intent.extras ?: return
|
||||||
|
val event = extras[Intent.EXTRA_KEY_EVENT] as Parcelable?
|
||||||
|
Timber.i("Got MEDIA_BUTTON key event: %s", event)
|
||||||
|
try {
|
||||||
|
val serviceIntent = Intent(Constants.CMD_PROCESS_KEYCODE)
|
||||||
|
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event)
|
||||||
|
lifecycleSupport.receiveIntent(serviceIntent)
|
||||||
|
if (isOrderedBroadcast) {
|
||||||
|
abortBroadcast()
|
||||||
|
}
|
||||||
|
} catch (x: Exception) {
|
||||||
|
// Ignored.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -146,10 +146,9 @@ class MediaPlayerController(
|
||||||
|
|
||||||
when {
|
when {
|
||||||
playerState === PlayerState.PAUSED -> {
|
playerState === PlayerState.PAUSED -> {
|
||||||
// TODO: Save playlist
|
playbackStateSerializer.serialize(
|
||||||
// playbackStateSerializer.serialize(
|
playList, currentMediaItemIndex, playerPosition
|
||||||
// downloader.getPlaylist(), downloader.currentPlayingIndex, playerPosition
|
)
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
playerState === PlayerState.STARTED -> {
|
playerState === PlayerState.STARTED -> {
|
||||||
scrobbler.scrobble(currentPlaying, false)
|
scrobbler.scrobble(currentPlaying, false)
|
||||||
|
|
Loading…
Reference in New Issue