Skip to content

Commit

Permalink
Remove isSpotifyAppActive (#222)
Browse files Browse the repository at this point in the history
* Bump iOS SDK to v3.0.0

* Update changelog

* Bump example app iOS version to 12

* Remove duplicate checkout

* Remove isActive from Android

* Remove isActive from iOS

* Update gradle

* update gradle properties

* update example

---------

Co-authored-by: Tobias Busch <tobi@minimalme.de>
  • Loading branch information
fotiDim and brim-borium authored Oct 5, 2024
1 parent 20d6f85 commit 62197b8
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 121 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.1
* **BREAKING**: `isSpotifyAppActive` is removed from iOS and Android (#222) and therefore removed from the sdk
* chore: Bump native iOS SDK to 3.0.0 (#222)

## 3.0.0
* All changes from dev builds
* chore: Bump native iOS SDK to 1.2.4 (#208)
Expand All @@ -13,7 +17,7 @@
* Feat: add set podcastPlaybackSpeed and switchToLocalDevice for android (#160)

## 3.0.0-dev.1
* **BREAKINg**:feat: update spotify.android:auth from 1.2.6 to 2.1.0 and spotify.app.remote from 0.7.2 to 0.8.0
* **BREAKING**:feat: update spotify.android:auth from 1.2.6 to 2.1.0 and spotify.app.remote from 0.7.2 to 0.8.0
In the app/build.gradle add the following to the default config for auth to work as described [here](https://github.com/spotify/android-auth#integrating-the-library-into-your-project)
```groovy
defaultConfig {
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ Token Swap is for now "web only". While the iOS SDK also supports the "token swa
| connectToSpotifyRemote | Connects the App to Spotify ||||
| getAccessToken | Gets the Access Token that you can use to work with the [Web Api](https://developer.spotify.com/documentation/web-api/) ||||
| disconnect | Disconnects the app connection ||||
| isSpotifyAppActive | Checks if the Spotify app is active. The Spotify app will be considered active if music is playing. ||| 🚧 |
| subscribeConnectionStatus | Subscribes to the current player state. ||| 🚧 |

#### Player Api
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:8.1.0'
classpath 'com.android.tools.build:gradle:8.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
5 changes: 3 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Thu Mar 05 21:24:22 CET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class SpotifyPlayerApi(spotifyAppRemote: SpotifyAppRemote?, result: MethodChanne
private val errorPodcastPlaybackSpeed = "podcastPlaybackSpeedError"
private val errorToggleShuffle = "toggleShuffleError"
private val errorToggleRepeat = "toggleRepeatError"
private val errorIsSpotifyAppActive = "isSpotifyAppActiveError"

private val playerApi = spotifyAppRemote?.playerApi

Expand Down Expand Up @@ -208,17 +207,4 @@ class SpotifyPlayerApi(spotifyAppRemote: SpotifyAppRemote?, result: MethodChanne
spotifyRemoteAppNotSetError()
}
}

internal fun isSpotifyAppActive() {
if (playerApi != null) {

playerApi.playerState
.setResultCallback { playerState -> result.success(!playerState.isPaused && playerState.playbackSpeed > 0)}
.setErrorCallback {
throwable -> result.error(errorIsSpotifyAppActive, "error when getting if spotify app is currently active/playing", throwable.toString())
}
} else {
spotifyRemoteAppNotSetError()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class SpotifySdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware, Plugin
private val methodToggleShuffle = "toggleShuffle"
private val methodSetShuffle = "setShuffle"
private val methodSetRepeatMode = "setRepeatMode"
private val methodIsSpotifyAppActive = "isSpotifyAppActive"

//userApi
private val methodAddToLibrary = "addToLibrary"
Expand Down Expand Up @@ -199,7 +198,6 @@ class SpotifySdkPlugin : MethodCallHandler, FlutterPlugin, ActivityAware, Plugin
methodSetShuffle -> spotifyPlayerApi?.setShuffle(call.argument(paramShuffle))
methodToggleRepeat -> spotifyPlayerApi?.toggleRepeat()
methodSetRepeatMode -> spotifyPlayerApi?.setRepeatMode(call.argument(paramRepeatMode))
methodIsSpotifyAppActive -> spotifyPlayerApi?.isSpotifyAppActive()
//userApi calls
methodAddToLibrary -> spotifyUserApi?.addToUserLibrary(call.argument(paramSpotifyUri))
methodRemoveFromLibrary -> spotifyUserApi?.removeFromUserLibrary(call.argument(paramSpotifyUri))
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version '8.1.0' apply false
id "com.android.application" version '8.7.0' apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
14 changes: 7 additions & 7 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -328,7 +328,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -351,7 +351,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -415,7 +415,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -464,7 +464,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -489,7 +489,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -521,7 +521,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
89 changes: 26 additions & 63 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,49 +81,33 @@ class HomeState extends State<Home> {

Widget _buildBottomBar(BuildContext context) {
return BottomAppBar(
height: 125,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedIconButton(
width: 50,
icon: Icons.queue_music,
onPressed: queue,
),
SizedIconButton(
width: 50,
icon: Icons.playlist_play,
onPressed: play,
),
SizedIconButton(
width: 50,
icon: Icons.repeat,
onPressed: toggleRepeat,
),
SizedIconButton(
width: 50,
icon: Icons.shuffle,
onPressed: toggleShuffle,
),
],
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedIconButton(
width: 50,
icon: Icons.queue_music,
onPressed: queue,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedIconButton(
width: 50,
onPressed: addToLibrary,
icon: Icons.favorite,
),
SizedIconButton(
width: 50,
onPressed: () => checkIfAppIsActive(context),
icon: Icons.info,
),
],
SizedIconButton(
width: 50,
icon: Icons.playlist_play,
onPressed: play,
),
SizedIconButton(
width: 50,
icon: Icons.repeat,
onPressed: toggleRepeat,
),
SizedIconButton(
width: 50,
icon: Icons.shuffle,
onPressed: toggleShuffle,
),
SizedIconButton(
width: 50,
onPressed: addToLibrary,
icon: Icons.favorite,
),
],
),
Expand Down Expand Up @@ -764,27 +748,6 @@ class HomeState extends State<Home> {
}
}

Future<void> checkIfAppIsActive(BuildContext context) async {
try {
final isActive = await SpotifySdk.isSpotifyAppActive;
_showSnackBar(isActive);
} on PlatformException catch (e) {
setStatus(e.code, message: e.message);
} on MissingPluginException {
setStatus('not implemented');
}
}

void _showSnackBar(bool isActive) {
final snackBar = SnackBar(
content: Text(isActive
? 'Spotify app connection is active (currently playing)'
: 'Spotify app connection is not active (currently not playing)'),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
}

void setStatus(String code, {String? message}) {
var text = message ?? '';
_logger.i('$code$text');
Expand Down
1 change: 0 additions & 1 deletion ios/Classes/SpotifySdkConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class SpotifySdkConstants
public static let methodConnectToSpotify = "connectToSpotify"
public static let methodGetAccessToken = "getAccessToken"
public static let methodDisconnectFromSpotify = "disconnectFromSpotify"
public static let methodCheckIfSpotifyAppIsActive = "isSpotifyAppActive"

//player api
public static let methodQueueTrack = "queueTrack"
Expand Down
4 changes: 0 additions & 4 deletions ios/Classes/SwiftSpotifySdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ public class SwiftSpotifySdkPlugin: NSObject, FlutterPlugin {
return
}
appRemote.playerAPI?.setRepeatMode(repeatMode, callback: defaultPlayAPICallback)
case SpotifySdkConstants.methodCheckIfSpotifyAppIsActive:
SPTAppRemote.checkIfSpotifyAppIsActive { isActive in
result(isActive)
}
case SpotifySdkConstants.getLibraryState:
guard let appRemote = appRemote else {
result(FlutterError(code: "Connection Error", message: "AppRemote is null", details: nil))
Expand Down
2 changes: 1 addition & 1 deletion ios/prepare-iOS-SDK.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ FRAMEWORK_NAME="SpotifyiOS.xcframework"
rm -fR ${REPO_NAME}
mkdir ${REPO_NAME}
git clone https://github.com/spotify/${REPO_NAME}
git -C ${REPO_NAME} checkout checkout tags/v2.1.7
git -C ${REPO_NAME} checkout tags/v3.0.0
find ./${REPO_NAME} -mindepth 1 -maxdepth 1 -not -name ${FRAMEWORK_NAME} -exec rm -rf '{}' \; # Keep on only the xcframework folder
3 changes: 0 additions & 3 deletions lib/platform_channels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class MethodNames {
/// method name for [disconnectFromSpotify]
static const String disconnectFromSpotify = 'disconnectFromSpotify';

/// method name for [isSpotifyAppActive]
static const String isSpotifyAppActive = 'isSpotifyAppActive';

/// method name for [getCrossfadeState]
static const String getCrossfadeState = 'getCrossfadeState';

Expand Down
16 changes: 0 additions & 16 deletions lib/spotify_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,6 @@ class SpotifySdk {
}
}

/// Checks if the Spotify app is active on the user's device. You can use this to determine if maybe you should prompt
/// the user to connect to Spotify (because you know they are already using Spotify if it is active). The Spotify app
/// will be considered active if music is playing.
/// Returns true if Spotify is active, otherwise false.
///
/// Throws a [MissingPluginException] if the method is not implemented on
/// the native platforms.
static Future<bool> get isSpotifyAppActive async {
try {
return await _channel.invokeMethod(MethodNames.isSpotifyAppActive);
} on Exception catch (e) {
_logException(MethodNames.isSpotifyAppActive, e);
rethrow;
}
}

/// Gets the current [CrossfadeState]
///
/// Throws a [PlatformException] getting the crossfadeState failed
Expand Down

0 comments on commit 62197b8

Please sign in to comment.