@@ -249,7 +249,7 @@ func (a *Application) Status() (*cast.Application, *cast.Media, *cast.Volume) {
249249
250250func (a * Application ) Pause () error {
251251 if a .media == nil {
252- return errors . New ( "media not yet initialised, there is nothing to pause" )
252+ return ErrNoMediaPause
253253 }
254254 return a .sendMediaRecv (& cast.MediaHeader {
255255 PayloadHeader : cast .PauseHeader ,
@@ -259,7 +259,7 @@ func (a *Application) Pause() error {
259259
260260func (a * Application ) Unpause () error {
261261 if a .media == nil {
262- return errors . New ( "media not yet initialised, there is nothing to unpause" )
262+ return ErrNoMediaUnpause
263263 }
264264 return a .sendMediaRecv (& cast.MediaHeader {
265265 PayloadHeader : cast .PlayHeader ,
@@ -269,7 +269,7 @@ func (a *Application) Unpause() error {
269269
270270func (a * Application ) StopMedia () error {
271271 if a .media == nil {
272- return errors . New ( "media not yet initialised, there is nothing to stop" )
272+ return ErrNoMediaStop
273273 }
274274 return a .sendMediaRecv (& cast.MediaHeader {
275275 PayloadHeader : cast .StopHeader ,
@@ -283,7 +283,7 @@ func (a *Application) Stop() error {
283283
284284func (a * Application ) Next () error {
285285 if a .media == nil {
286- return errors . New ( "media not yet initialised, there is nothing to go to next" )
286+ return ErrNoMediaNext
287287 }
288288
289289 // TODO(vishen): Get the number of queue items, if none, possibly just skip to the end?
@@ -296,7 +296,7 @@ func (a *Application) Next() error {
296296
297297func (a * Application ) Previous () error {
298298 if a .media == nil {
299- return errors . New ( "media not yet initialised, there is nothing previous" )
299+ return ErrNoMediaPrevious
300300 }
301301
302302 // TODO(vishen): Get the number of queue items, if none, possibly just jump to beginning?
@@ -310,7 +310,7 @@ func (a *Application) Previous() error {
310310func (a * Application ) Skip () error {
311311
312312 if a .media == nil {
313- return errors . New ( "media not yet initialised, there is nothing to skip" )
313+ return ErrNoMediaSkip
314314 }
315315
316316 // Get the latest media status
@@ -329,7 +329,7 @@ func (a *Application) Skip() error {
329329
330330func (a * Application ) Seek (value int ) error {
331331 if a .media == nil {
332- return errors . New ( "media not yet initialised" )
332+ return ErrMediaNotYetInitialised
333333 }
334334
335335 return a .sendMediaRecv (& cast.MediaHeader {
@@ -342,7 +342,7 @@ func (a *Application) Seek(value int) error {
342342
343343func (a * Application ) SeekFromStart (value int ) error {
344344 if a .media == nil {
345- return errors . New ( "media not yet initialised" )
345+ return ErrMediaNotYetInitialised
346346 }
347347
348348 // Get the latest media status
@@ -362,6 +362,28 @@ func (a *Application) SeekFromStart(value int) error {
362362 })
363363}
364364
365+ func (a * Application ) SetVolume (value float32 ) error {
366+ if value > 1 || value < 0 {
367+ return ErrVolumeOutOfRange
368+ }
369+
370+ return a .sendDefaultRecv (& cast.SetVolume {
371+ PayloadHeader : cast .VolumeHeader ,
372+ Volume : cast.Volume {
373+ Level : value ,
374+ },
375+ })
376+ }
377+
378+ func (a * Application ) SetMuted (value bool ) error {
379+ return a .sendDefaultRecv (& cast.SetVolume {
380+ PayloadHeader : cast .VolumeHeader ,
381+ Volume : cast.Volume {
382+ Muted : value ,
383+ },
384+ })
385+ }
386+
365387func (a * Application ) getMediaStatus () (* cast.MediaStatusResponse , error ) {
366388 apiMessage , err := a .sendAndWaitMediaRecv (& cast .GetStatusHeader )
367389 if err != nil {
@@ -695,7 +717,7 @@ func (a *Application) startStreamingServer() error {
695717 go func () {
696718 a .log ("media server listening on %d" , a .serverPort )
697719 if err := a .httpServer .Serve (listener ); err != nil && err != http .ErrServerClosed {
698- log .Fatal ( err )
720+ log .WithField ( "package" , "application" ). WithError ( err ). Fatal ( "error serving HTTP" )
699721 }
700722 }()
701723
@@ -719,14 +741,14 @@ func (a *Application) serveLiveStreaming(w http.ResponseWriter, r *http.Request,
719741 w .Header ().Set ("Transfer-Encoding" , "chunked" )
720742
721743 if err := cmd .Run (); err != nil {
722- log .Printf ( "error transcoding %q: %v " , filename , err )
744+ log .WithField ( "package " , "application" ). WithField ( " filename" , filename ). WithError ( err ). Error ( "error transcoding" )
723745 }
724746
725747}
726748
727749func (a * Application ) log (message string , args ... interface {}) {
728750 if a .debug {
729- log .Infof ( "[application] %s " , fmt . Sprintf (message , args ... ) )
751+ log .WithField ( "package " , "application" ). Infof (message , args ... )
730752 }
731753}
732754
@@ -778,15 +800,15 @@ func (a *Application) sendDefaultRecv(payload cast.Payload) error {
778800
779801func (a * Application ) sendMediaConn (payload cast.Payload ) error {
780802 if a .application == nil {
781- return errors . New ( "application isn't set" )
803+ return ErrApplicationNotSet
782804 }
783805 _ , err := a .send (payload , defaultSender , a .application .TransportId , namespaceConn )
784806 return err
785807}
786808
787809func (a * Application ) sendMediaRecv (payload cast.Payload ) error {
788810 if a .application == nil {
789- return errors . New ( "application isn't set" )
811+ return ErrApplicationNotSet
790812 }
791813 _ , err := a .send (payload , defaultSender , a .application .TransportId , namespaceMedia )
792814 return err
@@ -802,14 +824,14 @@ func (a *Application) sendAndWaitDefaultRecv(payload cast.Payload) (*pb.CastMess
802824
803825func (a * Application ) sendAndWaitMediaConn (payload cast.Payload ) (* pb.CastMessage , error ) {
804826 if a .application == nil {
805- return nil , errors . New ( "application isn't set" )
827+ return nil , ErrApplicationNotSet
806828 }
807829 return a .sendAndWait (payload , defaultSender , a .application .TransportId , namespaceConn )
808830}
809831
810832func (a * Application ) sendAndWaitMediaRecv (payload cast.Payload ) (* pb.CastMessage , error ) {
811833 if a .application == nil {
812- return nil , errors . New ( "application isn't set" )
834+ return nil , ErrApplicationNotSet
813835 }
814836 return a .sendAndWait (payload , defaultSender , a .application .TransportId , namespaceMedia )
815837}
0 commit comments