Commit 3d7832fe authored by Markus Seidl's avatar Markus Seidl

Added omxplayer as it seems better for raspberry pi (it's written specially for it).

parent daeb3b6a
......@@ -9,10 +9,11 @@ import (
const ConfigFile = "./config.json"
type BotConfig struct {
TelegramToken string
KnownIds map[int]bool
Password string
MPlayerCommandLineArgs []string
TelegramToken string
KnownIds map[int]bool
Password string
Player string
PlayerCommandLineArgs []string
}
func LoadConfig() BotConfig {
......@@ -22,9 +23,10 @@ func LoadConfig() BotConfig {
err := json.Unmarshal(configFileData, &config)
if err != nil {
StoreConfig(BotConfig{
TelegramToken: "token",
KnownIds: make(map[int]bool),
MPlayerCommandLineArgs: make([]string, 0),
TelegramToken: "token",
KnownIds: make(map[int]bool),
Player: "omxplayer",
PlayerCommandLineArgs: make([]string, 0),
})
log.Fatalf("Unable to load configfile <%s>. Writing empty file.\n", err.Error())
}
......
......@@ -4,7 +4,8 @@ import (
"log"
"os/exec"
"rgifbot/config"
"rgifbot/mplayer"
"rgifbot/player/mplayer"
"rgifbot/player/omxplayer"
"rgifbot/simpledb"
"runtime"
"time"
......@@ -15,13 +16,15 @@ func DisplayLoop(db *simpledb.Database) {
var addArgs []string
conf := config.LoadConfig()
if conf.MPlayerCommandLineArgs != nil && len(conf.MPlayerCommandLineArgs) > 0 {
addArgs = append(addArgs, conf.MPlayerCommandLineArgs...)
if conf.PlayerCommandLineArgs != nil && len(conf.PlayerCommandLineArgs) > 0 {
addArgs = append(addArgs, conf.PlayerCommandLineArgs...)
}
mplayer.StartSlave(func(err error) {
log.Printf("Error while communicating with mplayer <%v>", err)
}, addArgs...)
if conf.Player == "mplayer" {
mplayer.StartSlave(func(err error) {
log.Printf("Error while communicating with mplayer <%v>", err)
}, addArgs...)
}
go func() {
curvid := db.Rnd() // start with a random file
......@@ -29,7 +32,7 @@ func DisplayLoop(db *simpledb.Database) {
if curvid == "" {
time.Sleep(time.Millisecond * 500)
} else {
execute(curvid)
execute(conf, curvid)
}
curvid = db.Next(curvid)
......@@ -41,9 +44,14 @@ func DisplayLoop(db *simpledb.Database) {
}
}
func execute(file string) {
func execute(conf config.BotConfig, file string) {
log.Printf("Playing <%s>\n", file)
mplayer.PlayAndWait(file)
if conf.Player == "mplayer" {
mplayer.PlayAndWait(file)
} else if conf.Player == "omxplayer" {
omxplayer.PlayAndWait(conf, file)
}
}
func executeSimple(file string) {
......
......@@ -7,6 +7,14 @@
// http://www.mplayerhq.hu/DOCS/tech/slave.txt
//
//
//
//
// Doesn't work good on RPi... use it only for debugging on "real" PCs
//
//
//
package mplayer
import (
......
package omxplayer
import (
"log"
"os/exec"
"rgifbot/config"
)
func PlayAndWait(config config.BotConfig, file string) {
var args []string
app := "/usr/local/bin/omxplayer"
if len(config.PlayerCommandLineArgs) > 0 {
args = append(args, config.PlayerCommandLineArgs...)
}
args = append(args, "\""+file+"\"")
cmd := &exec.Cmd{
Path: app,
Args: args,
}
log.Printf("Executing: %s %v", app, args)
temp, err := cmd.CombinedOutput()
log.Print(err)
log.Print(string(temp))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment