-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e60a15d
commit 14c59e9
Showing
13 changed files
with
179 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
type Current struct { | ||
Movie CurrentMovie `json:"movie"` | ||
Status Status `json:"status"` | ||
} | ||
|
||
type CurrentMovie struct { | ||
ID string `json:"id,omitempty"` | ||
IsLive bool `json:"isLive,omitempty"` | ||
SubPath string `json:"subPath,omitempty"` | ||
} | ||
|
||
type Status struct { | ||
LastUpdate time.Time `json:"lastUpdate,omitempty"` | ||
CurrentTime float64 `json:"currentTime,omitempty"` | ||
PlaybackRate float64 `json:"playbackRate,omitempty"` | ||
IsPlaying bool `json:"isPlaying,omitempty"` | ||
} | ||
|
||
func NewStatus() Status { | ||
return Status{ | ||
CurrentTime: 0, | ||
PlaybackRate: 1.0, | ||
LastUpdate: time.Now(), | ||
} | ||
} | ||
|
||
func (c *Current) UpdateStatus() Status { | ||
if c.Movie.IsLive { | ||
c.Status.LastUpdate = time.Now() | ||
return c.Status | ||
} | ||
if c.Status.IsPlaying { | ||
c.Status.CurrentTime += time.Since(c.Status.LastUpdate).Seconds() * c.Status.PlaybackRate | ||
} | ||
c.Status.LastUpdate = time.Now() | ||
return c.Status | ||
} | ||
|
||
func (c *Current) setLiveStatus() Status { | ||
c.Status.IsPlaying = true | ||
c.Status.PlaybackRate = 1.0 | ||
c.Status.CurrentTime = 0 | ||
c.Status.LastUpdate = time.Now() | ||
return c.Status | ||
} | ||
|
||
func (c *Current) SetStatus(playing bool, seek, rate, timeDiff float64) Status { | ||
if c.Movie.IsLive { | ||
return c.setLiveStatus() | ||
} | ||
c.Status.IsPlaying = playing | ||
c.Status.PlaybackRate = rate | ||
if playing { | ||
c.Status.CurrentTime = seek + (timeDiff * rate) | ||
} else { | ||
c.Status.CurrentTime = seek | ||
} | ||
c.Status.LastUpdate = time.Now() | ||
return c.Status | ||
} | ||
|
||
func (c *Current) SetSeekRate(seek, rate, timeDiff float64) Status { | ||
if c.Movie.IsLive { | ||
return c.setLiveStatus() | ||
} | ||
if c.Status.IsPlaying { | ||
c.Status.CurrentTime = seek + (timeDiff * rate) | ||
} else { | ||
c.Status.CurrentTime = seek | ||
} | ||
c.Status.PlaybackRate = rate | ||
c.Status.LastUpdate = time.Now() | ||
return c.Status | ||
} | ||
|
||
func (c *Current) SetSeek(seek, timeDiff float64) Status { | ||
if c.Movie.IsLive { | ||
return c.setLiveStatus() | ||
} | ||
if c.Status.IsPlaying { | ||
c.Status.CurrentTime = seek + (timeDiff * c.Status.PlaybackRate) | ||
} else { | ||
c.Status.CurrentTime = seek | ||
} | ||
c.Status.LastUpdate = time.Now() | ||
return c.Status | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.