[GH-ISSUE #586] How to resume playback after pause_playback()? #349

Closed
opened 2026-02-27 23:22:08 +03:00 by kerem · 7 comments
Owner

Originally created by @jainal09 on GitHub (Oct 15, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/586

@app.route('/pause')
def pause():
    auth_manager = spotipy.oauth2.SpotifyOAuth(cache_path=session_cache_path())
    if not auth_manager.get_cached_token():
        return redirect('/')
    spotify = spotipy.Spotify(auth_manager=auth_manager)
    spotify.pause_playback()
    return redirect('/')

I have the following code that pause the current song.
But how do i resume the song after pause_playback()
or already paused song.

Originally created by @jainal09 on GitHub (Oct 15, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/586 ```python @app.route('/pause') def pause(): auth_manager = spotipy.oauth2.SpotifyOAuth(cache_path=session_cache_path()) if not auth_manager.get_cached_token(): return redirect('/') spotify = spotipy.Spotify(auth_manager=auth_manager) spotify.pause_playback() return redirect('/') ``` I have the following code that pause the current song. But how do i resume the song after pause_playback() or already paused song.
kerem 2026-02-27 23:22:08 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@stephanebruckert commented on GitHub (Oct 15, 2020):

https://spotipy.readthedocs.io/en/2.16.0/#spotipy.client.Spotify.start_playback

<!-- gh-comment-id:709434964 --> @stephanebruckert commented on GitHub (Oct 15, 2020): https://spotipy.readthedocs.io/en/2.16.0/#spotipy.client.Spotify.start_playback
Author
Owner

@jainal09 commented on GitHub (Oct 15, 2020):

@app.route('/play')
def play():
    auth_manager = spotipy.oauth2.SpotifyOAuth(cache_path=session_cache_path())
    if not auth_manager.get_cached_token():
        return redirect('/')
    spotify = spotipy.Spotify(auth_manager=auth_manager)
    spotify.start_playback()
    return redirect('/')

So when i tried the above code I got the following error
Player command failed: No active device found, reason: NO_ACTIVE_DEVICE

<!-- gh-comment-id:709447822 --> @jainal09 commented on GitHub (Oct 15, 2020): ```python @app.route('/play') def play(): auth_manager = spotipy.oauth2.SpotifyOAuth(cache_path=session_cache_path()) if not auth_manager.get_cached_token(): return redirect('/') spotify = spotipy.Spotify(auth_manager=auth_manager) spotify.start_playback() return redirect('/') ``` So when i tried the above code I got the following error `Player command failed: No active device found, reason: NO_ACTIVE_DEVICE`
Author
Owner

@jainal09 commented on GitHub (Oct 15, 2020):

Okay its very odd when I do first
pause_playback()
and then start_playback()
It runs fine!
But if i restart the flask app and directly try to call start_playback() i get the same error
Player command failed: No active device found, reason: NO_ACTIVE_DEVICE

<!-- gh-comment-id:709450112 --> @jainal09 commented on GitHub (Oct 15, 2020): Okay its very odd when I do first `pause_playback()` and then `start_playback()` It runs fine! But if i restart the flask app and directly try to call `start_playback()` i get the same error `Player command failed: No active device found, reason: NO_ACTIVE_DEVICE`
Author
Owner

@Peter-Schorn commented on GitHub (Oct 15, 2020):

@jainal09 I've found that devices can become inactive very quickly. Try accessing using the Spotify.devices method to get the user's available devices, and ensure that at least one is active. For testing purposes, trying doing this before each request to the start_playback() and pause_playback() methods.

<!-- gh-comment-id:709595540 --> @Peter-Schorn commented on GitHub (Oct 15, 2020): @jainal09 I've found that devices can become inactive very quickly. Try accessing using the `Spotify.devices` method to get the user's available devices, and ensure that at least one is active. For testing purposes, trying doing this before each request to the `start_playback()` and `pause_playback()` methods.
Author
Owner

@stephanebruckert commented on GitHub (Oct 19, 2020):

@jainal09 can you confirm whether you see any device using Spotify.devices() before attempting Spotify.start_playback()?

<!-- gh-comment-id:711782263 --> @stephanebruckert commented on GitHub (Oct 19, 2020): @jainal09 can you confirm whether you see any device using `Spotify.devices()` before attempting `Spotify.start_playback()`?
Author
Owner

@jainal09 commented on GitHub (Oct 21, 2020):

Yeh i solved the issue. What is interesting is @Peter-Schorn 's suggestion was right sometimes Spotify.devices() would not show device even if my spotify app is open in background in Windows 10 in paused mode.

<!-- gh-comment-id:713635214 --> @jainal09 commented on GitHub (Oct 21, 2020): Yeh i solved the issue. What is interesting is @Peter-Schorn 's suggestion was right sometimes `Spotify.devices()` would not show device even if my spotify app is open in background in Windows 10 in paused mode.
Author
Owner

@Peter-Schorn commented on GitHub (Oct 21, 2020):

The fact that a Spotify client is running doesn't necessarily mean it's considered an active device.

<!-- gh-comment-id:713645907 --> @Peter-Schorn commented on GitHub (Oct 21, 2020): The fact that a Spotify client is running doesn't necessarily mean it's considered an active device.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#349
No description provided.