summaryrefslogtreecommitdiff
path: root/player
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-01-13 20:28:25 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-01-13 20:28:25 (GMT)
commit69c143585a5b183e461ce5e0e1aa575911889ac3 (patch)
treee902fa480d9233a0df044c27d3cc14e424c9a493 /player
parent57d45bc46d23a8e9abbd707277425c2961a2b57d (diff)
player checks now if file exists before loading it
Diffstat (limited to 'player')
-rw-r--r--player/player.go18
1 files changed, 18 insertions, 0 deletions
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