Add FFplay support to the application
Integrated FFplay functionality across the application. This includes support for setting up the FFplay path and invoking FFplay for media playback.
This commit is contained in:
@@ -32,8 +32,10 @@ type ConvertorContract interface {
|
||||
GetTotalDuration(file *File) (float64, error)
|
||||
GetFFmpegVesrion() (string, error)
|
||||
GetFFprobeVersion() (string, error)
|
||||
GetFFplayVersion() (string, error)
|
||||
ChangeFFmpegPath(path string) (bool, error)
|
||||
ChangeFFprobePath(path string) (bool, error)
|
||||
ChangeFFplayPath(path string) (bool, error)
|
||||
GetRunningProcesses() map[int]*exec.Cmd
|
||||
GetSupportFormats() (encoder.ConvertorFormatsContract, error)
|
||||
}
|
||||
@@ -46,6 +48,7 @@ type ProgressContract interface {
|
||||
type FFPathUtilities struct {
|
||||
FFmpeg string
|
||||
FFprobe string
|
||||
FFplay string
|
||||
}
|
||||
|
||||
type runningProcesses struct {
|
||||
@@ -177,6 +180,17 @@ func (s Convertor) GetFFprobeVersion() (string, error) {
|
||||
return text[0], nil
|
||||
}
|
||||
|
||||
func (s Convertor) GetFFplayVersion() (string, error) {
|
||||
cmd := exec.Command(s.ffPathUtilities.FFplay, "-version")
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
text := regexp.MustCompile("\r?\n").Split(strings.TrimSpace(string(out)), -1)
|
||||
return text[0], nil
|
||||
}
|
||||
|
||||
func (s Convertor) ChangeFFmpegPath(path string) (bool, error) {
|
||||
cmd := exec.Command(path, "-version")
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
@@ -205,6 +219,20 @@ func (s Convertor) ChangeFFprobePath(path string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s Convertor) ChangeFFplayPath(path string) (bool, error) {
|
||||
cmd := exec.Command(path, "-version")
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if strings.Contains(strings.TrimSpace(string(out)), "ffplay") == false {
|
||||
return false, nil
|
||||
}
|
||||
s.ffPathUtilities.FFplay = path
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s Convertor) GetSupportFormats() (encoder.ConvertorFormatsContract, error) {
|
||||
formats := encoder.NewConvertorFormats()
|
||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, "-encoders")
|
||||
|
30
kernel/ffplay.go
Normal file
30
kernel/ffplay.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package kernel
|
||||
|
||||
import (
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type FFplay struct {
|
||||
ffPathUtilities *FFPathUtilities
|
||||
}
|
||||
|
||||
type FFplaySetting struct {
|
||||
PathToFile string
|
||||
}
|
||||
|
||||
type FFplayContract interface {
|
||||
Run(setting FFplaySetting) error
|
||||
}
|
||||
|
||||
func NewFFplay(ffPathUtilities *FFPathUtilities) *FFplay {
|
||||
return &FFplay{ffPathUtilities: ffPathUtilities}
|
||||
}
|
||||
|
||||
func (ffplay FFplay) Run(setting FFplaySetting) error {
|
||||
args := []string{setting.PathToFile}
|
||||
cmd := exec.Command(ffplay.ffPathUtilities.FFplay, args...)
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
|
||||
return cmd.Start()
|
||||
}
|
@@ -66,6 +66,7 @@ type QueueLayoutObject struct {
|
||||
items map[int]QueueLayoutItem
|
||||
localizerService LocalizerContract
|
||||
queueStatisticsFormat *queueStatisticsFormat
|
||||
ffplayService FFplayContract
|
||||
}
|
||||
|
||||
type QueueLayoutItem struct {
|
||||
@@ -73,11 +74,12 @@ type QueueLayoutItem struct {
|
||||
ProgressBar *widget.ProgressBar
|
||||
StatusMessage *canvas.Text
|
||||
MessageError *canvas.Text
|
||||
buttonPlay *widget.Button
|
||||
|
||||
status *StatusContract
|
||||
}
|
||||
|
||||
func NewQueueLayoutObject(queue QueueListContract, localizerService LocalizerContract) *QueueLayoutObject {
|
||||
func NewQueueLayoutObject(queue QueueListContract, localizerService LocalizerContract, ffplayService FFplayContract) *QueueLayoutObject {
|
||||
title := widget.NewLabel(localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "queue"}))
|
||||
title.TextStyle.Bold = true
|
||||
|
||||
@@ -98,6 +100,7 @@ func NewQueueLayoutObject(queue QueueListContract, localizerService LocalizerCon
|
||||
items: items,
|
||||
localizerService: localizerService,
|
||||
queueStatisticsFormat: queueStatisticsFormat,
|
||||
ffplayService: ffplayService,
|
||||
}
|
||||
|
||||
queue.AddListener(queueLayoutObject)
|
||||
@@ -121,11 +124,18 @@ func (o QueueLayoutObject) Add(id int, queue *Queue) {
|
||||
|
||||
statusMessage := canvas.NewText(o.getStatusTitle(queue.Status), theme.Color(theme.ColorNamePrimary))
|
||||
messageError := canvas.NewText("", theme.Color(theme.ColorNameError))
|
||||
buttonPlay := widget.NewButtonWithIcon("", theme.Icon(theme.IconNameMediaPlay), func() {
|
||||
|
||||
})
|
||||
buttonPlay.Hide()
|
||||
|
||||
content := container.NewVBox(
|
||||
container.NewHScroll(widget.NewLabel(queue.Setting.VideoFileInput.Name)),
|
||||
progressBar,
|
||||
container.NewHScroll(statusMessage),
|
||||
container.NewHScroll(container.NewHBox(
|
||||
buttonPlay,
|
||||
statusMessage,
|
||||
)),
|
||||
container.NewHScroll(messageError),
|
||||
canvas.NewLine(theme.Color(theme.ColorNameFocus)),
|
||||
container.NewPadded(),
|
||||
@@ -141,6 +151,7 @@ func (o QueueLayoutObject) Add(id int, queue *Queue) {
|
||||
ProgressBar: progressBar,
|
||||
StatusMessage: statusMessage,
|
||||
MessageError: messageError,
|
||||
buttonPlay: buttonPlay,
|
||||
status: &queue.Status,
|
||||
}
|
||||
o.container.Add(content)
|
||||
@@ -169,6 +180,20 @@ func (o QueueLayoutObject) ChangeQueueStatus(queueId int, queue *Queue) {
|
||||
item.MessageError.Refresh()
|
||||
})
|
||||
}
|
||||
if queue.Status == StatusType(Completed) {
|
||||
item.buttonPlay.Show()
|
||||
item.buttonPlay.OnTapped = func() {
|
||||
item.buttonPlay.Disable()
|
||||
go func() {
|
||||
_ = o.ffplayService.Run(FFplaySetting{
|
||||
PathToFile: queue.Setting.VideoFileOut.Path,
|
||||
})
|
||||
fyne.Do(func() {
|
||||
item.buttonPlay.Enable()
|
||||
})
|
||||
}()
|
||||
}
|
||||
}
|
||||
if o.queueStatisticsFormat.isChecked(queue.Status) == false && item.CanvasObject.Visible() == true {
|
||||
item.CanvasObject.Hide()
|
||||
} else if item.CanvasObject.Visible() == false {
|
||||
|
@@ -83,5 +83,7 @@ func (w Window) GetLayout() LayoutContract {
|
||||
}
|
||||
|
||||
func (w Window) SetOnDropped(callback func(position fyne.Position, uris []fyne.URI)) {
|
||||
w.windowFyne.SetOnDropped(callback)
|
||||
fyne.Do(func() {
|
||||
w.windowFyne.SetOnDropped(callback)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user