schreibfaul1 / ESP32-audioI2S

Play mp3 files from SD via I2S
GNU General Public License v3.0
1.12k stars 289 forks source link

Pause and play music #801

Closed Explorerlowi closed 1 month ago

Explorerlowi commented 3 months ago

How do I pause the music that is playing? After pausing, can I resume the music from where I paused it? If so, how do I do it?

schreibfaul1 commented 3 months ago

There is audio.pauseResume(); for this

Explorerlowi commented 3 months ago

屏幕截图 2024-08-08 131553 I'm playing the music above. 屏幕截图 2024-08-08 131610 Then I executed the pause instruction and called audio.pauseResume(); but the music was still playing and did not pause. 屏幕截图 2024-08-08 131625

Explorerlowi commented 3 months ago

屏幕截图 2024-08-08 131553 I'm playing the music above. 屏幕截图 2024-08-08 131610 Then I executed the pause instruction and called audio.pauseResume(); but the music was still playing and did not pause. 屏幕截图 2024-08-08 131625

When I use audio2.stopSong();, it can stop the music playing, but I don't know how to resume playing from the paused position

schreibfaul1 commented 3 months ago

perhaps the command is called several times? if(audio.isRunning()) audio.pauseResume();

Explorerlowi commented 3 months ago

I found the reason. When audio.loop() is executed, the m_streamType = ST_WEBSTREAM; set when playing music will be changed to m_streamType = ST_WEBFILE;. As a result, when audio.pauseResume() is called, the judgment of if (getDatamode() == AUDIO_LOCALFILE || m_streamType == ST_WEBSTREAM) does not hold, so the playback cannot be paused and resumed. 屏幕截图 2024-08-08 173237

Explorerlowi commented 3 months ago

I found the reason. When audio.loop() is executed, the m_streamType = ST_WEBSTREAM; set when playing music will be changed to m_streamType = ST_WEBFILE;. As a result, when audio.pauseResume() is called, the judgment of if (getDatamode() == AUDIO_LOCALFILE || m_streamType == ST_WEBSTREAM) does not hold, so the playback cannot be paused and resumed. 屏幕截图 2024-08-08 173237

Change the conditional judgment to if (getDatamode() == AUDIO_LOCALFILE || m_streamType == ST_WEBFILE) to pause and resume playback normally.

schreibfaul1 commented 3 months ago

PauseResume only works with local files. This is not always successful with web files. The server could disconnect if a timeout occurs.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 14 days since being marked as stale.