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

startPlayer() Restarts from Beginning After Progress Dragging #378

Open
shaniu00 opened this issue Dec 9, 2024 · 1 comment
Open

startPlayer() Restarts from Beginning After Progress Dragging #378

shaniu00 opened this issue Dec 9, 2024 · 1 comment
Labels
waiting-for-response Waiting for someone to respond.

Comments

@shaniu00
Copy link

shaniu00 commented Dec 9, 2024

Title: startPlayer() Restarts from Beginning After Progress Dragging
Description:
When using the startPlayer() method to play an audio file, the player always restarts from the beginning, even after seeking to a specific position using the seekTo() method. The issue occurs only after the user has dragged the progress bar to a specific position.

Steps to Reproduce:

Use seekTo() to set the playback position to a specific time (e.g., seekTo(2464)).
Call startPlayer() to begin playback from the specified position.
If the user interacts with the progress bar (even by tapping it), startPlayer() will restart the audio from the beginning, regardless of the previous position set by seekTo().
Expected Behavior: After calling seekTo() to jump to a specific position, the audio should start from that position when startPlayer() is invoked, without restarting from the beginning.

Actual Behavior: Every time startPlayer() is called after the user interacts with the progress bar, the audio starts from the beginning, even though the position was set previously using seekTo().

Code Example:

GestureDetector(
  onTap: () {
    if (_isPlaying) {
      getPlayerController(itemUrl).pausePlayer(); // Pause playback
    } else {
      print("Starting playback from position: ${UploadedProgress[itemUrl] ?? 0}");
      
      // Set playback position
      getPlayerController(itemUrl).seekTo(UploadedProgress[itemUrl] ?? 0);
      
      // Start playback from the specified position
      getPlayerController(itemUrl).startPlayer(forceRefresh: false);
    }
    setState(() {
      _isPlaying = !_isPlaying; // Toggle playback state
    });
  },
  child: Icon(
    _isPlaying ? Icons.pause_outlined : Icons.play_arrow,
    size: 30,
    color: Colors.white, // Icon color
  ),
),

Version of audio_waveforms package: 1.2.0 (or whichever version you're using)

Environment:

Flutter version: [Insert Flutter version here]
Android version: [Insert Android version here]
iOS version: [Insert iOS version here]
Additional Information: This issue is occurring when forceRefresh: false is passed in startPlayer(). Even though the player is supposed to continue from the current position, it restarts from the beginning every time it's invoked after seeking or user interaction.

Suggested Solution:
It seems that the forceRefresh flag in startPlayer() is causing the player to ignore the previous position and always reset to the start. If this flag is necessary, a separate flag to preserve the position might be required to avoid resetting the player to the beginning.

@ujas-m-simformsolutions
Copy link
Collaborator

@shaniu00 could UploadedProgress[itemUrl] be null because if it is null then it will start from beginning since you're you are seeking to 0 before starting the player.

@ujas-m-simformsolutions ujas-m-simformsolutions added the waiting-for-response Waiting for someone to respond. label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-response Waiting for someone to respond.
Projects
None yet
Development

No branches or pull requests

2 participants