Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
5rahim committed Sep 7, 2024
1 parent 8efcf5b commit 06d09df
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
5 changes: 5 additions & 0 deletions internal/mediaplayers/mpv/mpv.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ func New(logger *zerolog.Logger, socketName string, appPath string) *Mpv {
func (m *Mpv) launchPlayer(idle bool, filePath string, args ...string) error {
var err error

m.Logger.Trace().Msg("mpv: Launching player")

// Cancel previous goroutine context
if m.cancel != nil {
m.Logger.Trace().Msg("mpv: Cancelling previous context")
m.cancel()
}
// Cancel previous command context
if cmdCancel != nil {
m.Logger.Trace().Msg("mpv: Cancelling previous command context")
cmdCancel()
}
cmdCtx, cmdCancel = context.WithCancel(context.Background())
Expand Down Expand Up @@ -147,6 +150,8 @@ func (m *Mpv) launchPlayer(idle bool, filePath string, args ...string) error {
wg.Wait()
time.Sleep(1 * time.Second)

m.Logger.Debug().Msg("mpv: Player started")

return nil
}

Expand Down
14 changes: 7 additions & 7 deletions internal/torrentstream/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type (
currentTorrentStatus TorrentStatus
cancelFunc context.CancelFunc

mu sync.Mutex
//stopCh chan struct{} // Closed when the media player stops
mu sync.Mutex
stopCh chan struct{} // Closed when the media player stops
mediaPlayerPlaybackStatusCh chan *mediaplayer.PlaybackStatus // Continuously receives playback status
timeSinceLoggedSeeding time.Time
}
Expand All @@ -53,11 +53,11 @@ type (

func NewClient(repository *Repository) *Client {
ret := &Client{
repository: repository,
torrentClient: mo.None[*torrent.Client](),
currentFile: mo.None[*torrent.File](),
currentTorrent: mo.None[*torrent.Torrent](),
//stopCh: make(chan struct{}),
repository: repository,
torrentClient: mo.None[*torrent.Client](),
currentFile: mo.None[*torrent.File](),
currentTorrent: mo.None[*torrent.Torrent](),
stopCh: make(chan struct{}),
mediaPlayerPlaybackStatusCh: make(chan *mediaplayer.PlaybackStatus, 1),
}

Expand Down
6 changes: 5 additions & 1 deletion internal/torrentstream/playback.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func (r *Repository) listenToMediaPlayerEvents() {
}()
r.logger.Debug().Msg("torrentstream: Media player stopped event received")
// Stop the stream
r.StopStream()
_ = r.StopStream()
// Stop the server
//r.serverManager.stopServer()
//// Signal to client.go that the media player has stopped
//close(r.client.stopCh)
}()
case status := <-r.mediaPlayerRepositorySubscriber.StreamingPlaybackStatusCh:
go func() {
Expand Down
17 changes: 17 additions & 0 deletions internal/torrentstream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ func (r *Repository) StopStream() error {
return nil
}

//func (r *Repository) StopStream() error {
// defer func() {
// if r := recover(); r != nil {
// }
// }()
// r.logger.Info().Msg("torrentstream: Stopping stream")
//
// // Stop the client
// // This will stop the stream and close the server
// // This also sends the eventTorrentStopped event
// close(r.client.stopCh)
//
// r.logger.Info().Msg("torrentstream: Stream stopped")
//
// return nil
//}

func (r *Repository) DropTorrent() error {
r.logger.Info().Msg("torrentstream: Dropping last torrent")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function TorrentStreamOverlay() {
return (
<>
{!mediaPlayerStartedPlaying && <div className="w-full bg-gray-900 fixed top-0 left-0 z-[100]">
<ProgressBar isIndeterminate />
<ProgressBar size="sm" isIndeterminate />
</div>}
<div className="fixed left-0 top-8 w-full flex justify-center z-[100]">
<div className="bg-gray-900 rounded-full border lg:max-w-[50%] w-fit py-3 px-6 flex gap-2 items-center text-sm lg:text-base">
Expand Down

0 comments on commit 06d09df

Please sign in to comment.