Page 2 of 2
Re: Buttongadget and loadsound
Posted: Tue Jul 26, 2022 5:31 pm
by Stefan
Here is working code that describes the problem.
Code: Select all
Global homepage.s,pic1,pic2,aSound,testlisticongadget
;homepage="https://doko-lounge.de/"
homepage=""
Declare LoadingError(Type, Filename$)
Declare Loading(Type, Filename$, ObjectId)
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
InitSound()
OpenWindow(0,10,100,800,600,"TestWindow")
testlisticongadget=ListIconGadget(#PB_Any, 10,100, 290, 90, "picture", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
aSound=LoadSound(#PB_Any, homepage+"sound.wav")
pic1=LoadImage(#PB_Any, homepage+"freuen.png")
Procedure Loading(Type, Filename$, ObjectId)
Debug Filename$ + " loaded (id = " + ObjectId + ")"
If Filename$=homepage+"freuen.png"
AddGadgetItem(testlisticongadget, 1, "Picture 1", ImageID(pic1))
ImageGadget(#PB_Any,10,10,ImageWidth(pic1),ImageHeight(pic1),ImageID(pic1))
ButtonImageGadget(#PB_Any,10,50,ImageWidth(pic1),ImageHeight(pic1),ImageID(pic1))
EndIf
EndProcedure
Procedure LoadingError(Type, Filename$)
Debug Filename$ + ": loading error"
EndProcedure
Re: Buttongadget and loadsound
Posted: Tue Jul 26, 2022 6:12 pm
by Paul
Did you check the developer console like Peter suggested and see if you are being blocked for security reasons? (linking to external resources)
Re: Buttongadget and loadsound
Posted: Tue Jul 26, 2022 7:48 pm
by Stefan
The sound is blocked, I already wrote. The images are loaded. Hence my question, why does a loaded image work in an imagegadget, but not in a buttonimagegadget.
Re: Buttongadget and loadsound
Posted: Tue Jul 26, 2022 8:22 pm
by Paul
Updating my example code to reflect your layout and placing the resources in the proper folders, I'm seeing everything work as expected.
https://reelmedia.org/sbtest/indexb.html
Code: Select all
;/ Created with PureVision64 v6.00 x64
;/ Tue, 26 Jul 2022 12:12:13
;/ by Reel Media Productions
InitSound()
Declare Loaded(Type, Filename$, ObjectId)
Declare LoadingError(Type, Filename$, ObjectId)
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
#Window_Main=1
Global pic1,asound,testlisticongadget,testbutton
;- Load Stuff
Global pic1=LoadImage(#PB_Any,"data/pic.png")
Global asound=LoadSound(#PB_Any,"data/blip.wav")
#LoadedElementsIndex=2
Procedure.i Window_Main()
If OpenWindow(#Window_Main,0,0,331,197,"Test Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
testlisticongadget=ListIconGadget(#PB_Any, 10,100, 290, 90, "picture", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetItem(testlisticongadget, 1, "Picture 1", ImageID(pic1))
ImageGadget(#PB_Any,10,10,ImageWidth(pic1),ImageHeight(pic1),ImageID(pic1))
testbutton=ButtonImageGadget(#PB_Any,10,50,ImageWidth(pic1),ImageHeight(pic1),ImageID(pic1))
ProcedureReturn WindowID(#Window_Main)
EndIf
EndProcedure
Procedure CloseWindowEvent()
WindowID=EventWindow()
Select WindowID
Case #Window_Main
CloseWindow(#Window_Main)
EndSelect
EndProcedure
;- GadgetEvent Loop
Procedure GadgetEvent()
GadgetID=EventGadget()
Select GadgetID
Case testbutton
PlaySound(asound)
EndSelect
EndProcedure
Procedure Loaded(Type, Filename$, ObjectId)
Static SBLoadedElements
SBLoadedElements+1
Debug Str(SBLoadedElements)+": "+Filename$+" loaded"
If SBLoadedElements=#LoadedElementsIndex
;- Main Loop
If Window_Main()
BindEvent(#PB_Event_Gadget,@GadgetEvent())
BindEvent(#PB_Event_CloseWindow,@CloseWindowEvent())
EndIf
EndIf
EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId)
Debug Filename$+": loading error"
EndProcedure
Re: Buttongadget and loadsound
Posted: Tue Jul 26, 2022 9:55 pm
by Stefan
Maybe you didn't understand the problem, Paul?
Re: Buttongadget and loadsound
Posted: Tue Jul 26, 2022 10:29 pm
by Paul
Stefan wrote: Tue Jul 26, 2022 9:55 pm
Maybe you didn't understand the problem, Paul?
I guess I did not
I was trying to show that if you code it right and have the files in the right place, everything will work fine.
If you insist on cross linking resources, you will cause browser (CORS) errors and whatever else behind the scenes that will cause your app to break. Forms and gadgets may fail or not display correctly, things could become unresponsive, a gadget might display an image and then the browser stops running the script due to the internal errors before the next gadget gets a chance to display properly. Any number of issues.
Anyway, best of luck to you.
Re: Buttongadget and loadsound
Posted: Tue Jul 26, 2022 11:35 pm
by Peter
@Stefan:
ButtonImageGadget() and ListIconGadget() internally use the canvas command toDataURL(). This fails if CORS is missing.
The error message is: Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
(You will see this error message in the Developer Console, as I mentioned earlier).
The ImageGadget does not use toDataURL() but drawImage(), which seems to work.
For this reason, the image is displayed in the ImageGadget but not in the ButtonImageGadget or ListIconGadget.
Re: Buttongadget and loadsound
Posted: Wed Jul 27, 2022 7:10 am
by Stefan
Very nice explanations, Peter and Paul, thank you very much!