Shuttle2 icon indicating copy to clipboard operation
Shuttle2 copied to clipboard

Fix playback reporting to media servers

Open timusus opened this issue 3 months ago • 0 comments

This commit resolves issue #96 by adding playback reporting functionality for remote media servers. The implementation follows the existing architecture patterns and integrates seamlessly with the playback system.

Changes:

  1. Created PlaybackReportingService for each provider:

    • Jellyfin: POST /Sessions/Playing, /Playing/Progress, /Playing/Stopped
    • Emby: Same endpoints as Jellyfin (compatible API)
    • Plex: GET /:/timeline for state updates, /:/scrobble for completion
  2. Added PlaybackInfo data classes for each provider:

    • Jellyfin/Emby: PlaybackStartInfo, PlaybackProgressInfo, PlaybackStopInfo
    • Plex: Uses query parameters with PlaybackState enum
  3. Updated DI modules to provide PlaybackReportingService instances:

    • JellyfinMediaProviderModule
    • EmbyMediaProviderModule
    • PlexMediaProviderModule
  4. Created PlaybackReporter coordinator class:

    • Implements PlaybackWatcherCallback to listen for playback events
    • Routes reporting to appropriate service based on Song.mediaProvider
    • Manages session IDs and progress reporting intervals (10s)
    • Handles playback start, progress updates, pause/resume, and stop
    • Only reports for remote providers (not local files)
  5. Created PlaybackReporterInitializer:

    • Registers PlaybackReporter with PlaybackWatcher on app startup
    • Integrated via AppModuleBinds using Hilt's multibinding

Architecture:

  • Follows Observer pattern (PlaybackWatcherCallback)
  • Uses Strategy pattern for provider-specific implementations
  • Dependency injection via Hilt for all components
  • Coroutine-based async operations
  • Proper error handling with Timber logging

Benefits:

  • Jellyfin/Emby/Plex servers now receive "now playing" updates
  • Server dashboards show active playback sessions
  • Playback history is tracked on the server side
  • Play counts and progress are synced to servers
  • No changes required to existing playback logic

Fixes #96

timusus avatar Nov 16 '25 06:11 timusus