Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Skip ahead/back Button #399

Open
extremelyonline opened this issue Feb 15, 2023 · 9 comments
Open

[Feature Request] Skip ahead/back Button #399

extremelyonline opened this issue Feb 15, 2023 · 9 comments
Labels
good first issue Good for newcomers hacktoberfest Issues available for Hacktoberfest

Comments

@extremelyonline
Copy link

On the (Android) lock screen/media interface, it would be great if there are buttons to skip ahead and back 15/30 seconds.

This would be very helpful for podcast listening. Perhaps there could be an option to let users decide between "next/previous tracks" mode and "skip ahead/back" mode?

@Chaphasilor Chaphasilor added good first issue Good for newcomers hacktoberfest Issues available for Hacktoberfest labels Oct 2, 2023
@Guillergood
Copy link
Contributor

I can take this, if assigned to me 😄

@Chaphasilor
Copy link
Collaborator

Sure, go ahead! It would be nice if you could add a setting to choose which buttons are shown, just like extremelyonline suggested :)

@Guillergood
Copy link
Contributor

@Chaphasilor / @jmshrv could you point me to see the notification widget? I am kind of lost in this huge project 😓

@Chaphasilor
Copy link
Collaborator

@Guillergood try starting here:

https://github.com/jmshrv/finamp/blob/main/lib/services/music_player_background_task.dart#L604-L609

Otherwise, check out the documentation for audio_service, there you should find info about customizing the notification!

@Guillergood Guillergood removed their assignment Dec 15, 2023
@vijayabhaskar78
Copy link

vijayabhaskar78 commented Oct 17, 2024

@Chaphasilor Can I work on this issue

@Chaphasilor
Copy link
Collaborator

@vijayabhaskar78 sure, go ahead. You should make the buttons configurable (shown or hidden) in the settings, with the default being hidden.
You could also reuse the logic used for showing the playback speed setting in the player screen menu (Settings > Layout & Theme > Customization > "Playback Speed Visibility" set to "Automatic), where it is only shown for tracks with certain lengths or genres.

Feel free to open a draft PR if you're stuck!

@vijayabhaskar78
Copy link

@Chaphasilor Here's a brief overview of the planned changes with some sample code:

  1. Adding new settings:

class FinampSettings {
// Existing fields...
bool useSkipButtons;
Duration skipDuration;
SkipButtonVisibility skipButtonVisibility;
}

enum SkipButtonVisibility {
always,
automatic,
never
}

  1. Implementing skip methods in MusicPlayerBackgroundTask:

Future skipAhead(Duration duration) async {
try {
final newPosition = _player.position + duration;
await _player.seek(newPosition);
} catch (e) {
_audioServiceBackgroundTaskLogger.severe(e);
return Future.error(e);
}
}

  1. Updating UI controls:

PlaybackState _transformEvent(PlaybackEvent event) {
// ... existing code ...
if (settings.skipButtonVisibility == SkipButtonVisibility.always ||
(settings.skipButtonVisibility == SkipButtonVisibility.automatic &&
shouldShowSkipButtons(currentTrack))) {
controls.insert(0, MediaControl.rewind);
controls.add(MediaControl.fastForward);
}
// ... rest of the method ...
}

  1. Logic for automatic visibility:

bool shouldShowSkipButtons(MediaItem mediaItem) {
final settings = FinampSettingsHelper.finampSettings;
if (settings.skipButtonVisibility == SkipButtonVisibility.automatic) {
final duration = mediaItem.duration;
final genre = mediaItem.genre;
return (duration != null && duration > Duration(minutes: 10)) ||
(genre != null && genre.toLowerCase().contains('podcast'));
}
return settings.skipButtonVisibility == SkipButtonVisibility.always;
}

I'll be submitting a pull request soon with these changes. Let me know if you'd like to discuss any aspects of the implementation before I proceed.

@Chaphasilor
Copy link
Collaborator

Hey, that looks mostly good, nice!
A few notes:

  • There is probably a method within the AudioPlayer class from just_audio (which is being implemented in music_player_background_task) that is related to seeking back and forth. If you implement that instead of adding your own method it would also be supported through Bluetooth commands or Android Audio, if those should happen to support it.
  • It might make sense to also show these controls in the media notification itself. That could be another boolean setting
  • Why do you want to make the skip duration customizable? And if we do that, shouldn't be make the forward and backward skip durations independent? There are a lot of apps where it's 10s back and 30s forward or something similar.
  • Make sure when adding new controls into the layout handler of the player screen to make sure the buttons are hidden for smaller screen sizes where there's not enough space, instead of overflowing the screen

It's probably best to just open a draft request and ask any remaining questions there, so that we can actually try things out and see if there's anything missing :)

@vijayabhaskar78
Copy link

@Chaphasilor Please check my pull request #932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest Issues available for Hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants