Skip to content

Commit

Permalink
Fix enum casting for playback speed
Browse files Browse the repository at this point in the history
  • Loading branch information
brim-borium committed Feb 6, 2022
1 parent f984aaa commit 11e1caa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class SpotifyPlayerApi(spotifyAppRemote: SpotifyAppRemote?, result: MethodChanne
internal fun setPodcastPlaybackSpeed(podcastPlaybackSpeedValue: Int?) {
if (playerApi != null && podcastPlaybackSpeedValue != null) {

val podcastPlaybackSpeed = PlaybackSpeed.PodcastPlaybackSpeed.values()[podcastPlaybackSpeedValue]
val podcastPlaybackSpeed = PlaybackSpeed.PodcastPlaybackSpeed.values().firstOrNull{ it.value == podcastPlaybackSpeedValue }

playerApi.setPodcastPlaybackSpeed(podcastPlaybackSpeed)
.setResultCallback { result.success(true) }
Expand Down Expand Up @@ -221,4 +221,4 @@ class SpotifyPlayerApi(spotifyAppRemote: SpotifyAppRemote?, result: MethodChanne
spotifyRemoteAppNotSetError()
}
}
}
}
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
43 changes: 43 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,37 @@ class _HomeState extends State<Home> {
),
],
),
track.isPodcast
? Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
child: const SizedBox(
width: 50,
child: Text("x0.5"),
),
onPressed: () => setPlaybackSpeed(
PodcastPlaybackSpeed.playbackSpeed_50),
),
TextButton(
child: const SizedBox(
width: 50,
child: Text("x1"),
),
onPressed: () => setPlaybackSpeed(
PodcastPlaybackSpeed.playbackSpeed_100),
),
TextButton(
child: const SizedBox(
width: 50,
child: Text("x1.5"),
),
onPressed: () => setPlaybackSpeed(
PodcastPlaybackSpeed.playbackSpeed_150),
),
],
)
: Container(),
Text(
'${track.name} by ${track.artist.name} from the album ${track.album.name}'),
Row(
Expand Down Expand Up @@ -543,6 +574,18 @@ class _HomeState extends State<Home> {
}
}

Future<void> setPlaybackSpeed(
PodcastPlaybackSpeed podcastPlaybackSpeed) async {
try {
await SpotifySdk.setPodcastPlaybackSpeed(
podcastPlaybackSpeed: podcastPlaybackSpeed);
} on PlatformException catch (e) {
setStatus(e.code, message: e.message);
} on MissingPluginException {
setStatus('not implemented');
}
}

Future<void> play() async {
try {
await SpotifySdk.play(spotifyUri: 'spotify:track:58kNJana4w5BIjlZE2wq5m');
Expand Down

0 comments on commit 11e1caa

Please sign in to comment.