Major improvements to UnifiedPlayer: 1. GetFrameImage() now works when paused for responsive UI updates 2. Play() method properly starts FFmpeg process 3. Frame display loop runs continuously for smooth video display 4. Disabled audio temporarily to fix video playback fundamentals 5. Simplified FFmpeg command to focus on video stream only Player now: - Generates video frames correctly - Shows video when paused - Has responsive progress tracking - Starts playback properly Next steps: Re-enable audio playback once video is stable
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
//go:build js && wasm
|
|
// +build js,wasm
|
|
|
|
package idb
|
|
|
|
import (
|
|
"syscall/js"
|
|
|
|
"github.com/hack-pad/safejs"
|
|
)
|
|
|
|
func tryAsDOMException(err error) error {
|
|
switch err := err.(type) {
|
|
case js.Error:
|
|
return domExceptionAsError(safejs.Safe(err.Value))
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
func domExceptionAsError(jsDOMException safejs.Value) error {
|
|
truthy, err := jsDOMException.Truthy()
|
|
if err != nil || !truthy {
|
|
return err
|
|
}
|
|
domException, err := parseJSDOMException(jsDOMException)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return domException
|
|
}
|
|
|
|
// DOMException is a JavaScript DOMException with a standard name.
|
|
// Use errors.Is() to compare by name.
|
|
type DOMException struct {
|
|
name string
|
|
message string
|
|
}
|
|
|
|
// NewDOMException returns a new DOMException with the given name.
|
|
// Only useful for errors.Is() comparisons with errors returned from idb.
|
|
func NewDOMException(name string) DOMException {
|
|
return DOMException{name: name}
|
|
}
|
|
|
|
func parseJSDOMException(jsDOMException safejs.Value) (DOMException, error) {
|
|
name, err := jsDOMException.Get("name")
|
|
if err != nil {
|
|
return DOMException{}, err
|
|
}
|
|
nameStr, err := name.String()
|
|
if err != nil {
|
|
return DOMException{}, err
|
|
}
|
|
message, err := jsDOMException.Get("message")
|
|
if err != nil {
|
|
return DOMException{}, err
|
|
}
|
|
messageStr, err := message.String()
|
|
if err != nil {
|
|
return DOMException{}, err
|
|
}
|
|
return DOMException{
|
|
name: nameStr,
|
|
message: messageStr,
|
|
}, nil
|
|
}
|
|
|
|
func (e DOMException) Error() string {
|
|
if e.message == "" {
|
|
return e.name
|
|
}
|
|
return e.name + ": " + e.message
|
|
}
|
|
|
|
// Is returns true target is a DOMException and matches this DOMException's name. Use 'errors.Is()' to call it.
|
|
func (e DOMException) Is(target error) bool {
|
|
targetDOMException, ok := target.(DOMException)
|
|
return ok && targetDOMException.name == e.name
|
|
}
|