Fix: gen current resp miss change movie filed

pull/79/head
zijiren233 2 years ago
parent fa13c96412
commit bdab999f95

@ -43,7 +43,7 @@ func newStatus() Status {
func (c *current) Current() Current { func (c *current) Current() Current {
c.lock.RLock() c.lock.RLock()
defer c.lock.RUnlock() defer c.lock.RUnlock()
c.current.UpdateSeek() c.current.UpdateStatus()
return c.current return c.current
} }
@ -63,7 +63,7 @@ func (c *current) SetMovie(movie *model.Movie, play bool) {
func (c *current) Status() Status { func (c *current) Status() Status {
c.lock.RLock() c.lock.RLock()
defer c.lock.RUnlock() defer c.lock.RUnlock()
c.current.UpdateSeek() c.current.UpdateStatus()
return c.current.Status return c.current.Status
} }
@ -81,15 +81,16 @@ func (c *current) SetSeekRate(seek, rate, timeDiff float64) Status {
return c.current.SetSeekRate(seek, rate, timeDiff) return c.current.SetSeekRate(seek, rate, timeDiff)
} }
func (c *Current) UpdateSeek() { func (c *Current) UpdateStatus() Status {
if c.Movie.Base.Live { if c.Movie.Base.Live {
c.Status.lastUpdate = time.Now() c.Status.lastUpdate = time.Now()
return return c.Status
} }
if c.Status.Playing { if c.Status.Playing {
c.Status.Seek += time.Since(c.Status.lastUpdate).Seconds() * c.Status.Rate c.Status.Seek += time.Since(c.Status.lastUpdate).Seconds() * c.Status.Rate
} }
c.Status.lastUpdate = time.Now() c.Status.lastUpdate = time.Now()
return c.Status
} }
func (c *Current) setLiveStatus() Status { func (c *Current) setLiveStatus() Status {

@ -89,33 +89,32 @@ func genCurrentRespWithCurrent(ctx context.Context, user *op.User, room *op.Room
if err != nil { if err != nil {
return nil, err return nil, err
} }
var movie *dbModel.Movie = &opMovie.Movie var movie = opMovie.Movie
if current.Movie.Base.VendorInfo.Vendor != "" { if movie.Base.VendorInfo.Vendor != "" {
vendorMovie, err := genVendorMovie(ctx, user, opMovie) vendorMovie, err := genVendorMovie(ctx, user, opMovie)
if err != nil { if err != nil {
return nil, err return nil, err
} }
movie = vendorMovie movie = *vendorMovie
} else if current.Movie.Base.RtmpSource || current.Movie.Base.Live && current.Movie.Base.Proxy { } else if movie.Base.RtmpSource || movie.Base.Live && movie.Base.Proxy {
switch current.Movie.Base.Type { switch movie.Base.Type {
case "m3u8": case "m3u8":
current.Movie.Base.Url = fmt.Sprintf("/api/movie/live/hls/list/%s.m3u8", current.Movie.ID) movie.Base.Url = fmt.Sprintf("/api/movie/live/hls/list/%s.m3u8", movie.ID)
case "flv": case "flv":
current.Movie.Base.Url = fmt.Sprintf("/api/movie/live/flv/%s.flv", current.Movie.ID) movie.Base.Url = fmt.Sprintf("/api/movie/live/flv/%s.flv", movie.ID)
default: default:
return nil, errors.New("not support live movie type") return nil, errors.New("not support live movie type")
} }
current.Movie.Base.Headers = nil movie.Base.Headers = nil
} else if current.Movie.Base.Proxy { } else if movie.Base.Proxy {
current.Movie.Base.Url = fmt.Sprintf("/api/movie/proxy/%s/%s", current.Movie.RoomID, current.Movie.ID) movie.Base.Url = fmt.Sprintf("/api/movie/proxy/%s/%s", movie.RoomID, movie.ID)
current.Movie.Base.Headers = nil movie.Base.Headers = nil
} }
if current.Movie.Base.Type == "" && current.Movie.Base.Url != "" { if movie.Base.Type == "" && movie.Base.Url != "" {
current.Movie.Base.Type = utils.GetUrlExtension(current.Movie.Base.Url) movie.Base.Type = utils.GetUrlExtension(movie.Base.Url)
} }
current.UpdateSeek()
resp := &model.CurrentMovieResp{ resp := &model.CurrentMovieResp{
Status: current.Status, Status: current.UpdateStatus(),
Movie: model.MoviesResp{ Movie: model.MoviesResp{
Id: movie.ID, Id: movie.ID,
CreatedAt: movie.CreatedAt.UnixMilli(), CreatedAt: movie.CreatedAt.UnixMilli(),

Loading…
Cancel
Save