I am trying to compile the example from https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/blob/main/video/gtk4/examples/gtksink.py . I need to write it in Haskell and I’m currently stuck on the paintable = gtksink.get_property('paintable')
function written in Python. I’ve searched around and found objectGetProperty
from the Gi-GObject library which seems like the one that I need. However I can’t seem to get it to work because it asks me for a GValue
of some kind in its third argument. I have tried to pass it a lot of stuff but nothing seems correct.
This is my code up so far:
{-# LANGUAGE OverloadedStrings, OverloadedLabels, ImplicitParams #-}
import Control.Monad (void)
import System.Environment (getArgs, getProgName)
import Data.Int (Int32)
import qualified GHC.Foreign as GHC
import qualified GI.Gtk as Gtk
import qualified GI.Gdk as Gdk
import qualified GI.Gsk as Gsk
import qualified GI.Gio as Gio
import qualified GI.GObject as GObject
import qualified GI.Gst as Gst
import qualified GI.GLib as GLib
import qualified Data.Text as T
import Data.GI.Base
activate :: Gtk.Application -> IO ()
activate app = do
pipeline <- Gst.pipelineNew (Just ("pippo"))
gtksink <- Gst.elementFactoryMake "gtk4paintablesink" (Just ("pluto"))
paintable <- GObject.objectGetProperty gtksink "paintable" 0
player <- Gtk.videoNew
Gtk.videoSetAutoplay player True
file_to_play <- Gio.fileNewForPath ("D:/stack-projects/gtk-intro-twelve/big-buck-bunny_trailer.webm")
Gtk.videoSetFile player (Just (file_to_play))
window <- new Gtk.ApplicationWindow [#application := app,
#title := "Hello",
#child := player]
#setDefaultSize window 1427 1080
#show window
main :: IO ()
main = do
app <- new Gtk.Application [#applicationId := "haskell-gi.Gtk4.test",
On #activate (activate ?self)]
-- If the application does not need to parse command line arguments
-- just pass Nothing.
args <- getArgs
progName <- getProgName
void $ #run app (Just $ progName : args)
It compiles with the errors:
D:stack-projectsgtk-intro-twelveappMain.hs:46:16: error: [GHC-05617]
* Could not solve: `Data.GI.Base.Overloading.CheckForAncestorType
(Maybe Gst.Element)
GObject.Object
(Data.GI.Base.Overloading.ParentTypes (Maybe Gst.Element))'
arising from a use of `GObject.objectGetProperty'
* In a stmt of a 'do' block:
paintable <- GObject.objectGetProperty gtksink "paintable" 0
In the expression:
do pipeline <- Gst.pipelineNew (Just ("pippo"))
gtksink <- Gst.elementFactoryMake
"gtk4paintablesink" (Just ("pluto"))
paintable <- GObject.objectGetProperty gtksink "paintable" 0
player <- Gtk.videoNew
....
In an equation for `activate':
activate app
= do pipeline <- Gst.pipelineNew (Just ("pippo"))
gtksink <- Gst.elementFactoryMake
"gtk4paintablesink" (Just ("pluto"))
paintable <- GObject.objectGetProperty gtksink "paintable" 0
....
|
46 | paintable <- GObject.objectGetProperty gtksink "paintable" 0
| ^^^^^^^^^^^^^^^^^^^^^^^^^
D:stack-projectsgtk-intro-twelveappMain.hs:46:16: error: [GHC-39999]
* No instance for `GObject (Maybe Gst.Element)'
arising from a use of `GObject.objectGetProperty'
* In a stmt of a 'do' block:
paintable <- GObject.objectGetProperty gtksink "paintable" 0
In the expression:
do pipeline <- Gst.pipelineNew (Just ("pippo"))
gtksink <- Gst.elementFactoryMake
"gtk4paintablesink" (Just ("pluto"))
paintable <- GObject.objectGetProperty gtksink "paintable" 0
player <- Gtk.videoNew
....
In an equation for `activate':
activate app
= do pipeline <- Gst.pipelineNew (Just ("pippo"))
gtksink <- Gst.elementFactoryMake
"gtk4paintablesink" (Just ("pluto"))
paintable <- GObject.objectGetProperty gtksink "paintable" 0
....
|
46 | paintable <- GObject.objectGetProperty gtksink "paintable" 0
| ^^^^^^^^^^^^^^^^^^^^^^^^^
D:stack-projectsgtk-intro-twelveappMain.hs:46:62: error: [GHC-39999]
* No instance for `Num GValue' arising from the literal `0'
* In the third argument of `GObject.objectGetProperty', namely `0'
In a stmt of a 'do' block:
paintable <- GObject.objectGetProperty gtksink "paintable" 0
In the expression:
do pipeline <- Gst.pipelineNew (Just ("pippo"))
gtksink <- Gst.elementFactoryMake
"gtk4paintablesink" (Just ("pluto"))
paintable <- GObject.objectGetProperty gtksink "paintable" 0
player <- Gtk.videoNew
....
|
46 | paintable <- GObject.objectGetProperty gtksink "paintable" 0
| ^
I have started from the https://github.com/haskell-gi/haskell-gi/blob/master/examples/Gtk4/gtk4-example.hs example, I’m trying to display a video through Gtk4.
I’ve tried looking online at the docs.gtk.org website, I looked at the GObject
class and read something about having to first install properties before accessing them with install_properties
and GParamSpecs
but I’m not sure I’m on the right track. Do you mind explaining to me what I’m doing wrong? I’ve been stuck on this for hours. Thank you in advance.