From 69c143585a5b183e461ce5e0e1aa575911889ac3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 13 Jan 2016 21:28:25 +0100 Subject: player checks now if file exists before loading it diff --git a/player/player.go b/player/player.go index 95bab81..90c607c 100644 --- a/player/player.go +++ b/player/player.go @@ -29,6 +29,7 @@ import ( "github.com/spreadspace/go-gstreamer" "io/ioutil" "log" + "os" "path" ) @@ -109,6 +110,23 @@ func (p *Player) onMessage(msg *gst.Message) { func (p *Player) load(cart, cut uint) (resp loadResult) { filename := path.Join(p.basepath, fmt.Sprintf("%06d_%03d.wav", cart, cut)) + + var file *os.File + if file, resp.err = os.Open(filename); resp.err != nil { + resp.err = fmt.Errorf("player: %s", resp.err) + return + } + if info, err := file.Stat(); err != nil { + resp.err = fmt.Errorf("player: %s", err) + return + } else { + if info.IsDir() { + resp.err = fmt.Errorf("player error: '%s' is a directory", filename) + return + } + } + file.Close() + p.pipe.SetProperty("uri", "file://"+filename) p.pipe.SetState(gst.STATE_PAUSED) return -- cgit v0.10.2