QWebEngineView Cannot Load Twitch Video Streams

I’ve been working with PyQt5’s QWebEngineView widget to display Twitch content, but I’m running into issues where video streams won’t play properly. The web engine loads the page but fails to start the actual video playback.

The console shows these error messages:

js: Player stopping playback - error MasterPlaylist:11 (ErrorNotAvailable code 404 - Failed to load playlist)
js: Player stopping playback - error Player:2 (ErrorNotSupported code 0 - No playable format)

Does anyone know what might be causing this problem? I’ve tried enabling different web engine settings but nothing seems to work. Alternative methods for streaming Twitch content in Python applications would also be helpful.

Here’s my current implementation:

from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import QUrl
import sys

class StreamViewer(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setupUI()
        
    def setupUI(self):
        self.setWindowTitle("Stream Player")
        self.setGeometry(100, 100, 1000, 600)
        
    def loadStream(self, channel_name):
        self.browser = QWebEngineView(self)
        config = self.browser.settings()
        config.setAttribute(QWebEngineSettings.PluginsEnabled, True)
        config.setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True)
        
        self.browser.setGeometry(0, 30, self.width(), self.height() - 30)
        self.browser.load(QUrl(f"https://www.twitch.tv/{channel_name}"))
        self.browser.show()

if __name__ == "__main__":
    application = QApplication(sys.argv)
    viewer = StreamViewer()
    viewer.show()
    viewer.loadStream("example_streamer")
    sys.exit(application.exec_())

yeah, i’ve had the same issues. twitch’s been cracking down on webengine. maybe try setting PlaybackRequiresUserGesture to false? you can also enable JavascriptCanAccessClipboard. but honestly, use streamlink with vlc python bindings. it’s way smoother for streaming.

Those errors usually come from Twitch’s content protection and codec issues. QWebEngineView struggles with modern streaming sites, as it lacks proprietary codecs and can’t handle DRM properly. I’ve found that setting additional web engine attributes, particularly for enabling JavaScript and local storage, can help. You might also need to spoof the user agent since Twitch restricts access from automated browsers. However, I would recommend avoiding the browser approach altogether. Instead, consider using the Twitch API to retrieve stream URLs and metadata, then direct that into VLC’s Python bindings or mpv for playback. This method is cleaner and allows you to bypass the limitations of a web browser.

twitch’s DRM can be a pain. try changing your user-agent string, or maybe look into using an iframe for better results. also, libraries like streamlink might help with streams. hope that helps!

Had the same problem building a streaming app last year. Twitch cracked down on bot detection and CDN access - your errors show they’re blocking you at the manifest level before video even loads.

I fixed it by setting up proper sessions with cookies and headers that look like real browser traffic. You’ve got to handle their OAuth flow correctly and keep session state alive. Just heads up though - Twitch actively fights automated stream access since it breaks their TOS.

Better option is their official embed system with the player API. Gives you legit stream access in apps, handles all the DRM/codec stuff automatically, and keeps you on the right side of their rules.

WebEngineProfile configuration fixed this exact issue for me. Your setup isn’t handling the profile correctly, and that’s critical for Twitch streaming. Create a custom profile and set the HTTP user agent to mimic a real browser - Twitch definitely detects QtWebEngine’s default signature and blocks it. You’re also missing WebGL and hardware acceleration settings. Without these, the stream might load but performance will suck. Add WebGLEnabled and Accelerated2dCanvasEnabled to your setAttribute calls. Honestly though, QWebEngineView isn’t great for this anymore. Twitch keeps changing things and breaking compatibility. I switched to using their embedded player in a minimal HTML wrapper instead - way fewer headaches and you still get interface control.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.