PureBasic_MiniBrowser_2003_example_modified_2017

Share your advanced PureBasic knowledge/code with the community.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

PureBasic_MiniBrowser_2003_example_modified_2017

Post by VB6_to_PBx »

PureBasic_MiniBrowser_2003_example_modified_2017

https://www.purebasic.com/french/docume ... er.pb.html

replace YouTube Video Links with your own

Code: Select all

;-< Top >
;-
;-       PureBasic_MiniBrowser_2003_example_modified_2017_v1.pb
;-      
;-       Original Link : https://www.purebasic.com/french/documentation/Examples/WebBrowser.pb.html
;-
;-       Link : http://www.purebasic.fr/english/viewtopic.php?p=93126#p93126
;-       Post Subject/Date : PostPosted: Wed Jun 15, 2005 11:59 am  modified by Dare2 year 2005
;-       Compiler : PB 5.31 ( July 22 2017 )
;-      
;-< Start Program >------------------------------------------------------------
;
;
; ------------------------------------------------------------
;
;   PureBasic - MiniBrowser
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;
; This program requiers the Microsoft freely distribuable
; ATL.dll shared library.
;

Define.i Cnt

Procedure ResizeWebWindow()
        ResizeGadget(10, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-52)
        ResizeGadget(4, #PB_Ignore, #PB_Ignore, WindowWidth(0)-185, #PB_Ignore)
        ResizeGadget(5, WindowWidth(0)-25, #PB_Ignore, #PB_Ignore, #PB_Ignore)
        ResizeGadget(6, #PB_Ignore, #PB_Ignore, WindowWidth(0), #PB_Ignore)
EndProcedure


If OpenWindow(0, 100, 200, 940, 705, "PureBasic MiniBrowser v1.0   Click [Next] Button = view next Video   [Back] Button = view previous Video", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)

    CreateStatusBar(0, WindowID(0))
         AddStatusBarField(#PB_Ignore)
         StatusBarText(0, 0, "Welcome to the world's smallest Browser ! :)", 0)
     
    ButtonGadget(1,   0, 0, 50, 25, "Back")
    ButtonGadget(2,  50, 0, 50, 25, "Next")
    ButtonGadget(3, 100, 0, 50, 25, "Quit")
    StringGadget(4, 155, 5, 0, 20, "https://www.purebasic.com/french/documentation/Examples/WebBrowser.pb.html" )
    ButtonGadget(5, 0, 0, 25, 25, "Go")
    FrameGadget(6, 0, 30, 0, 2, "", 2) ; Nice little separator

;-  Note : need to Parse https://www.youtube.com/watch?v=CD1CYMPNSis   to only this -> https://www.youtube.com/v/CD1CYMPNSis
    If WebGadget(10, 0, 31, 0, 0, "https://www.youtube.com/v/CD1CYMPNSis") = 0 : MessageRequester("Error", "ATL.dll not found", 0) : End : EndIf
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
    ResizeWebWindow()
 
    Repeat
         Event = WaitWindowEvent()
   
         Select Event
         Case #PB_Event_Gadget
              Select EventGadget()
              Case 1 : SetGadgetState(10, #PB_Web_Back)
              Case 2 : SetGadgetState(10, #PB_Web_Forward)
                       Select Cnt   ;------ put your own YouTube Video Links here 
                       Case 0 : Cnt = Cnt + 1 : SetGadgetText(10, "https://www.youtube.com/v/1Qcexr6CZ5Y")
                       Case 1 : Cnt = Cnt + 1 : SetGadgetText(10, "https://www.youtube.com/v/V1wWKOAdS38")
                       Case 2 : Cnt = Cnt + 1 : SetGadgetText(10, "https://www.youtube.com/v/wTG-bCMG05E")
                       Case 3 : Cnt = Cnt + 1 : SetGadgetText(10, "https://www.youtube.com/v/qoX0Olfqziw")
                       Case 4 : Cnt = Cnt + 1 : SetGadgetText(10, "https://www.youtube.com/v/tZugz8FTqog")
                       Case 5 : Cnt = Cnt + 1 : SetGadgetText(10, "https://www.youtube.com/v/euMNVyuqmwo")
                       Case 6 : Cnt = 0 : SetGadgetText(10, "https://www.youtube.com/v/CD1CYMPNSis")
                       EndSelect
              Case 3 : SetGadgetState(10, #PB_Web_Stop) : End
              Case 5 : SetGadgetText(10, GetGadgetText(4))
              EndSelect     
         Case #PB_Event_Menu ; We only have one shortcut
              SetGadgetText(10, GetGadgetText(4))
         Case #PB_Event_SizeWindow : ResizeWebWindow()
         Case #PB_Event_CloseWindow:SetGadgetState(10, #PB_Web_Stop) : CloseWindow(0) : End
         EndSelect
    ForEver
EndIf


;-
;-< End Program >--------------------------------------------------------------

Last edited by VB6_to_PBx on Sat Jul 22, 2017 10:10 pm, edited 1 time in total.
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by chris319 »

I added this line to your mini-browser so that the CloseWindow gadget actually works:

Code: Select all

Case #PB_Event_CloseWindow:SetGadgetState(10, #PB_Web_Stop) :CloseWindow(0): End
I also changed this line so that the window opens at 0,0, otherwise you're throwing away a lot of screen real estate, which is not good if you're going to view videos.

Code: Select all

If OpenWindow(0, 0, 0, 940, 705, "PureBasic MiniBrowser v1.0", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by VB6_to_PBx »

chris319 wrote:I added this line to your mini-browser so that the CloseWindow gadget actually works:

Code: Select all

Case #PB_Event_CloseWindow:SetGadgetState(10, #PB_Web_Stop) :CloseWindow(0): End
I also changed this line so that the window opens at 0,0, otherwise you're throwing away a lot of screen real estate, which is not good if you're going to view videos.

Code: Select all

If OpenWindow(0, 0, 0, 940, 705, "PureBasic MiniBrowser v1.0", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)

Thank you very much chris319 , for the new Code change !

i completely forgot to fix the "CloseWindow = End program" code :oops:
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by chris319 »

You might like this if you're interested in playing YouTube videos:

http://leaderswest.com/2012/10/10/youtu ... youtube-y/

My video player fills the screen with video. I don't know if it's possible to read a video's height & width so that I could adjust the size of my playback to maintain the video's original aspect ratio.

I still get the YouTube control bar at the bottom of my videos but it goes away after a few seconds.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by VB6_to_PBx »

chris319 wrote:You might like this if you're interested in playing YouTube videos:

http://leaderswest.com/2012/10/10/youtu ... youtube-y/

My video player fills the screen with video. I don't know if it's possible to read a video's height & width so that I could adjust the size of my playback to maintain the video's original aspect ratio.

I still get the YouTube control bar at the bottom of my videos but it goes away after a few seconds.
i just edited my first Post above, and included you new code fix for closing Program

thanks Chris , i made a FireFox Bookmark of "leaderswest.com/2012/10/10/youtube-embed-options-can-make-your-videos-look-less-youtube-y" Link
will take a closer look at that webpage

on another Subject : Forum Videos
here's Flash .FLV and .MP4 PhpBB Forum code that works pretty well all the time in Forums with Flash enabled

Code: Select all

[flash=640,480]https://www.youtube.com/v/CD1CYMPNSis[/flash]
i'll test out different things from your webpage link
and see if i can make them work in Forum PhpBB codes

i've been able to play PhotoBucket *.MP4 videos in Forum PhpBB codes in the Flash player
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by chris319 »

I hope to make it possible to pause and start the video with the space bar and control the volume with the cursor up/down keys. I could then set controls=0 and not get that YouTube-y stuff.

I wonder if we could get the YouTube iframe api to work with PB.

This stuff is all new to me.

https://developers.google.com/youtube/i ... _reference

Vimeo also has an api.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by chris319 »

This is from the YouTube API:
Getting started

The sample HTML page below creates an embedded player that will load a video, play it for six seconds, and then stop the playback. The numbered comments in the HTML are explained in the list below the example.

Code: Select all

<!DOCTYPE html>
<html>
  <body>
    <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
    <div id="player"></div>

    <script>
      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'M7lc1UVf-VE',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }

      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.playVideo();
      }

      // 5. The API calls this function when the player's state changes.
      //    The function indicates that when playing a video (state=1),
      //    the player should play for six seconds and then stop.
      var done = false;
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING && !done) {
          setTimeout(stopVideo, 6000);
          done = true;
        }
      }
      function stopVideo() {
        player.stopVideo();
      }
    </script>
  </body>
</html>
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by chris319 »

This changes my plans. I could set controls to 0 and enable the keyboard.
controls
This parameter indicates whether the video player controls are displayed. For IFrame embeds that load a Flash player, it also defines when the controls display in the player as well as when the player will load. Supported values are:
controls=0 – Player controls do not display in the player. For IFrame embeds, the Flash player loads immediately.
disablekb
Setting the parameter's value to 1 causes the player to not respond to keyboard controls. The default value is 0, which means that keyboard controls are enabled. Currently supported keyboard controls are:
Spacebar or [k]: Play / Pause
Arrow Left: Jump back 5 seconds in the current video
Arrow Right: Jump ahead 5 seconds in the current video
Arrow Up: Volume up
Arrow Down: Volume Down
[f]: Toggle full-screen display
[j]: Jump back 10 seconds in the current video
[l]: Jump ahead 10 seconds in the current video
[m]: Mute or unmute the video
[0-9]: Jump to a point in the video. 0 jumps to the beginning of the video, 1 jumps to the point 10% into the video, 2 jumps to the point 20% into the video, and so forth.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by VB6_to_PBx »

Spacebar or [k]: Play / Pause
Arrow Left: Jump back 5 seconds in the current video
Arrow Right: Jump ahead 5 seconds in the current video
Arrow Up: Volume up
Arrow Down: Volume Down
[f]: Toggle full-screen display
[j]: Jump back 10 seconds in the current video
[l]: Jump ahead 10 seconds in the current video
[m]: Mute or unmute the video
[0-9]: Jump to a point in the video. 0 jumps to the beginning of the video, 1 jumps to the point 10% into the video, 2 jumps to the point 20% into the video, and so forth.
all these Keyboard Keys so far work with the PB MiniBrowser in 1st Post , its using Adobe Flash Player
however, the NumberLock Keypad Numbers do not have any effect , so just use the regular upper row Keyboard Numbers instead .

Also ,
i think it would be great if entire Internet would switch over to HTML5 Players
instead of Adobe Flash Players

Adobe = way too many bugs and version fixes thru the years ,
along with always trying to push McAfee AntiVirus software bundled into Flash Player Updates/Upgrades

the only one good thing about Adobe's .FLV file size is smaller than .MP4 most of time
for same video quality
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by chris319 »

How have you determined that we're looking at videos with Flash (crash) player?

Agreed that flash player is a bit of a disaster. YouTube does support HTML5 but I kind of doubt PB does.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by VB6_to_PBx »

How have you determined that we're looking at videos with Flash (crash) player?
right-click on the video screen while a video is playing or loaded in the MiniBrowser above
and you should see a popup window with the last sentence stating About Adobe Flash Player version xxxxxx something

its because PB's WebGadget is using old InternetExplorer files ( even while using FireFox Browser , etc )
but you can do a lot of different things with PB 's WebGadget instead of just looking at YouTube Videos .
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: PureBasic_MiniBrowser_2003_example_modified_2017

Post by chris319 »

Flash player might be a bonus in my case because it seems to render the colors accurately.

Anything associated with Firefox will likely have inaccurate colors. I have been after three Firefox programmers to get the colors right and it has even been written up as an official bug. The crux of the problem is that they use DXVA hardware acceleration (in Windows) and it default to the bt.601 color space, rather than the sRGB standard color space, bt.709.

Microsoft Edge and IE both default to bt.709.
Post Reply