I am trying to display a video using Gtk4 and Haskell but I’m having some trouble doing this.
Here is my code up so far. I have modified the example from https://github.com/haskell-gi/haskell-gi/blob/master/examples/Gtk4/gtk4-example.hs and I now have this.
{-# LANGUAGE OverloadedStrings, OverloadedLabels, ImplicitParams #-}
import Control.Monad (void)
import System.Environment (getArgs, getProgName)
import Data.Int (Int32)
import qualified GI.Gtk as Gtk
import Data.GI.Base
activate :: Gtk.Application -> IO ()
activate app = do
--img1 <- Gtk.pictureNewForFilename (Just ("D:/stack-projects/gtk-intro-twelve/redbus"))
--img3 <- "D:/stack-projects/gtk-intro-twelve/Glossaryck-4.png"
--img2 <- Gtk.pictureGetFile img3
--img <- Gtk.pictureSetFilename (Just "D:/stack-projects/gtk-intro-twelve/Glossaryck-4.png")
video1 <- Gtk.pictureNewForPaintable (Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
-- #append box img1
window <- new Gtk.ApplicationWindow [#application := app,
#title := "Hello",
#child := video1]
#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)
I have first tried to print an image on screen using img1 <- Gtk.pictureNewForFilename (Just ("D:/stack-projects/gtk-intro-twelve/Glossaryck-4.png"))
and it worked.
I then tried doing the same with img1 <- Gtk.pictureNewForFilename (Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
to output the requested video but it didn’t work.
So then I tried with video1 <- Gtk.pictureNewForPaintable (Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
but it threw the error
D:stack-projectsgtk-intro-twelveappMain.hs:19:13: error: [GHC-10283]
* Couldn't match representation of type `a0'
with that of `ManagedPtr ()'
arising from a superclass required to satisfy `Coercible
a0 (ManagedPtr ())',
arising from a superclass required to satisfy `ManagedPtrNewtype
a0',
arising from a superclass required to satisfy `GObject a0',
arising from a use of `Gtk.pictureNewForPaintable'
* In a stmt of a 'do' block:
video1 <- Gtk.pictureNewForPaintable
(Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
In the expression:
do video1 <- Gtk.pictureNewForPaintable
(Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
window <- new
Gtk.ApplicationWindow
[#application := app, #title := "Hello", ....]
#setDefaultSize window 1427 1080
#show window
In an equation for `activate':
activate app
= do video1 <- Gtk.pictureNewForPaintable
(Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
window <- new Gtk.ApplicationWindow [#application := app, ....]
#setDefaultSize window 1427 1080
....
|
19 | video1 <- Gtk.pictureNewForPaintable (Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: [S-7282]
Stack failed to execute the build plan.
I don’t know what this means. I’m guessing it has something to do with GObject and the fact that I should somehow first turn the variable video1
into a GObject? But I’m not really sure. Could you point me in the right direction?