我正在尝试使用 Gtk4 和 Haskell 显示视频,但我在执行此操作时遇到了一些问题。 这是到目前为止我的代码。我已经修改了 https://github.com/haskell-gi/haskell-gi/blob/master/examples/Gtk4/gtk4-example.hs 中的示例,现在我有了这个。
{-# 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)
我首先尝试使用
img1 <- Gtk.pictureNewForFilename (Just ("D:/stack-projects/gtk-intro-twelve/Glossaryck-4.png"))
在屏幕上打印图像,并且成功了。
然后我尝试用 img1 <- Gtk.pictureNewForFilename (Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
执行相同的操作来输出请求的视频,但它不起作用。
然后我尝试使用
video1 <- Gtk.pictureNewForPaintable (Just ("D:/stack-projects/gtk-intro-twelve/redbus.mp4"))
但它引发了错误
D:\stack-projects\gtk-intro-twelve\app\Main.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.
我不知道这意味着什么。我猜这与 GObject 有关,事实上我应该首先将变量
video1
转换为 GObject?但我不太确定。你能指出我正确的方向吗?