QB64.org Forum

Active Forums => Programs => Topic started by: SMcNeill on January 12, 2021, 11:14:48 am

Title: Pop-Up Video
Post by: SMcNeill on January 12, 2021, 11:14:48 am
Code: QB64: [Select]
  1. PlayVideo _CWD$ + "\" + "test.mp4"
  2.  
  3. SUB PlayVideo (file$)
  4.     ff = FREEFILE
  5.     OPEN "playmovie.ps1" FOR OUTPUT AS #1
  6.  
  7.     PRINT #1, "Add-Type -AssemblyName presentationCore"
  8.     PRINT #1, "$filepath = [uri] " + CHR$(34) + file$ + CHR$(34)
  9.     PRINT #1, "$wmplayer = New-Object System.Windows.Media.MediaPlayer"
  10.     PRINT #1, "$wmplayer.Open($filepath)"
  11.     PRINT #1, "$duration = $wmplayer.NaturalDuration.TimeSpan.Seconds"
  12.     PRINT #1, "$wmplayer.Close()"
  13.     PRINT #1, ""
  14.     PRINT #1, "$proc = Start-process -FilePath wmplayer.exe -ArgumentList $filepath"
  15.     CLOSE
  16.     SHELL _HIDE "Powershell.exe -File playmovie.ps1"
  17.  
  18.  

A quick little powershell script to pop up a video and play it in Windows.  Personally, I'm a little disappointed in this here, as I still haven't sorted out a good method to know when to close the external program, position it, or size it, but I'm certain those options are probably all in Powershell somewhere -- even if I don't know where, yet!  ;P

Anyone with more experience with powershell and this sort of thing, is more than welcome to help expand on this little demo and hopefully highlight the things I'm missing out on.  ;D
Title: Re: Pop-Up Video
Post by: Pete on January 12, 2021, 12:42:07 pm
Isn't just easier to SHELL to an installed media player, or your default media player?

Example:

Code: QB64: [Select]
  1. SHELL _HIDE _DONTWAIT "vlc.exe myvid.mp4"

Pete
Title: Re: Pop-Up Video
Post by: Pete on January 12, 2021, 12:44:52 pm
Oh, and to terminate it, for Windows, you might want to look into using the API to get the handle, and then terminate it with taskkill.

Pete
Title: Re: Pop-Up Video
Post by: SMcNeill on January 12, 2021, 01:03:39 pm
Isn't just easier to SHELL to an installed media player, or your default media player?

Example:

Code: QB64: [Select]
  1. SHELL _HIDE _DONTWAIT "vlc.exe myvid.mp4"

Pete

But are you certain someone else’s PC will have VLC installed?  All my windows machines run powershell, but not all of them use the same video playback programs.
Title: Re: Pop-Up Video
Post by: Pete on January 12, 2021, 03:06:08 pm
Ah, but I also stated you can just use whatever default media player is installed...

Code: QB64: [Select]
  1. SHELL _HIDE _DONTWAIT "myvid.mp4"

In the old days, we used to have to use CMD / C, and in Win98 and below COMMAND /C along with START to accomplish that...

Code: QB64: [Select]
  1. SHELL "cmd /c START myvid.mp4"

Note that QB64 still supports START. START was meant to use the operating system to find the program, regardless of the directory, and to use a default device, if none was specified. That's the way I remember it, anyway.

Pete
Title: Re: Pop-Up Video
Post by: SpriggsySpriggs on January 12, 2021, 03:34:14 pm
@SMcNeill

Hooray for PowerShell!
Title: Re: Pop-Up Video
Post by: SMcNeill on January 12, 2021, 10:55:07 pm
I'm getting much closer to what I'm looking for with this here:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. _SCREENMOVE 200, 200
  3.  
  4.  
  5.  
  6.  
  7. PlayVideo _CWD$ + "\" + "test.mp4", 100, 100
  8.  
  9.  
  10. SUB PlayVideo (file$, x, y)
  11.         FUNCTION glutGet& (BYVAL what&)
  12.     END DECLARE
  13.  
  14.     ff = FREEFILE
  15.     OPEN "playmovie.ps1" FOR OUTPUT AS #1
  16.  
  17.     PRINT #ff, "WPF Library for Playing Movie and some components"
  18.     PRINT #ff, "Add-Type -AssemblyName PresentationFramework"
  19.     PRINT #ff, "Add-Type -AssemblyName System.ComponentModel"
  20.     PRINT #ff, "#XAML File of WPF as windows for playing movie"
  21.     PRINT #ff, "[xml]$XAML = @" + CHR$(34)
  22.     PRINT #ff, ""
  23.     PRINT #ff, "<Window xmlns=" + CHR$(34) + "http://schemas.microsoft.com/winfx/2006/xaml/presentation" + CHR$(34)
  24.     PRINT #ff, "        xmlns:x=" + CHR$(34) + "http://schemas.microsoft.com/winfx/2006/xaml" + CHR$(34)
  25.     PRINT #ff, "        Title=" + CHR$(34) + "PowerShell Video Player" + CHR$(34) + " Height=" + CHR$(34) + "480" + CHR$(34) + " Width=" + CHR$(34) + "640" + CHR$(34)
  26.     'PRINT #ff, "        WindowStyle=" + CHR$(34) + "None" + CHR$(34)
  27.     PRINT #ff, "        Left=" + CHR$(34) + _TRIM$(STR$(glutGet(100) + x)) + CHR$(34) + " Top=" + CHR$(34) + _TRIM$(STR$(glutGet(101) + y)) + CHR$(34) + " ResizeMode=" + CHR$(34) + "NoResize" + CHR$(34) + ">"
  28.     PRINT #ff, "    <Grid Margin=" + CHR$(34) + "0,0,2,3" + CHR$(34) + ">"
  29.     PRINT #ff, "        <MediaElement Height=" + CHR$(34) + "480" + CHR$(34) + " Width=" + CHR$(34) + "640" + CHR$(34) + " Name=" + CHR$(34) + "VideoPlayer" + CHR$(34) + " LoadedBehavior=" + CHR$(34) + "Manual" + CHR$(34) + " UnloadedBehavior=" + CHR$(34) + "Stop" + CHR$(34) + " Margin=" + CHR$(34) + "8,10,10,61" + CHR$(34) + " />"
  30.     PRINT #ff, "        <Button Content=" + CHR$(34) + "Pause" + CHR$(34) + " Name=" + CHR$(34) + "PauseButton" + CHR$(34) + " HorizontalAlignment=" + CHR$(34) + "Left" + CHR$(34) + " Margin=" + CHR$(34) + "236,383,0,0" + CHR$(34) + " VerticalAlignment=" + CHR$(34) + "Top" + CHR$(34) + " Width=" + CHR$(34) + "75" + CHR$(34) + "/>"
  31.     PRINT #ff, "        <Button Content=" + CHR$(34) + "Play" + CHR$(34) + " Name=" + CHR$(34) + "PlayButton" + CHR$(34) + " HorizontalAlignment=" + CHR$(34) + "Left" + CHR$(34) + " Margin=" + CHR$(34) + "236,383,0,0" + CHR$(34) + " VerticalAlignment=" + CHR$(34) + "Top" + CHR$(34) + " Width=" + CHR$(34) + "75" + CHR$(34) + "/>"
  32.     PRINT #ff, "    </Grid>"
  33.     PRINT #ff, "</Window>"
  34.     PRINT #ff, CHR$(34) + "@"
  35.     PRINT #ff, ""
  36.     PRINT #ff, "#Movie Path"
  37.     PRINT #ff, "[uri]$VideoSource = " + CHR$(34) + file$ + CHR$(34)
  38.     PRINT #ff, ""
  39.     PRINT #ff, "#Devide All Objects on XAML"
  40.     PRINT #ff, "$XAMLReader=(New-Object System.Xml.XmlNodeReader $XAML)"
  41.     PRINT #ff, "$Window=[Windows.Markup.XamlReader]::Load( $XAMLReader )"
  42.     PRINT #ff, "$VideoPlayer = $Window.FindName(" + CHR$(34) + "VideoPlayer" + CHR$(34) + ")"
  43.     PRINT #ff, "$PauseButton = $Window.FindName(" + CHR$(34) + "PauseButton" + CHR$(34) + ")"
  44.     PRINT #ff, "$PlayButton = $Window.FindName(" + CHR$(34) + "PlayButton" + CHR$(34) + ")"
  45.     PRINT #ff, ""
  46.     PRINT #ff, "#Video Default Setting"
  47.     PRINT #ff, "$VideoPlayer.Volume = 100;"
  48.     PRINT #ff, "$VideoPlayer.Source = $VideoSource;"
  49.     PRINT #ff, "$VideoPlayer.Play()"
  50.     PRINT #ff, "$PauseButton.Visibility = [System.Windows.Visibility]::Visible"
  51.     PRINT #ff, "$PlayButton.Visibility = [System.Windows.Visibility]::Hidden"
  52.     PRINT #ff, ""
  53.     PRINT #ff, "#Button click event"
  54.     PRINT #ff, "$PlayButton.Add_Click({"
  55.     PRINT #ff, "    $VideoPlayer.Play()"
  56.     PRINT #ff, "    $PauseButton.Visibility = [System.Windows.Visibility]::Visible"
  57.     PRINT #ff, "    $PlayButton.Visibility = [System.Windows.Visibility]::Hidden"
  58.     PRINT #ff, "})"
  59.     PRINT #ff, "$PauseButton.Add_Click({"
  60.     PRINT #ff, "    $VideoPlayer.Pause()"
  61.     PRINT #ff, "    $PauseButton.Visibility = [System.Windows.Visibility]::Hidden"
  62.     PRINT #ff, "    $PlayButton.Visibility = [System.Windows.Visibility]::Visible"
  63.     PRINT #ff, "})"
  64.     PRINT #ff, ""
  65.     PRINT #ff, "#Show Up the Window"
  66.     PRINT #ff, "$Window.ShowDialog() | out-null"
  67.     CLOSE
  68.     SHELL _HIDE "Powershell.exe -File playmovie.ps1"
  69.  

The main thing I'm lacking here is now someway to calculate the movie time and then auto-close the task, and I'll have a pop-up video player to use with a few programs in windows.  :)
Title: Re: Pop-Up Video
Post by: Pete on January 12, 2021, 11:24:29 pm
Again, why not just download a media player, that can be configured to close upon completion like VLC?

Pete
Title: Re: Pop-Up Video
Post by: SMcNeill on January 12, 2021, 11:35:27 pm
Again, why not just download a media player, that can be configured to close upon completion like VLC?

Pete

Because I'm shooting for something native which I can share with others, without expecting them to download other programs which they might not be interested in. 

Because I'm old, and like to reinvent the wheel.  You should appreciate this, as you like to recreate text editors and word processes, rather than downloading OpenOffice, Word, or any of the other numerous ones out there.

Just because.  :P
Title: Re: Pop-Up Video
Post by: Pete on January 12, 2021, 11:37:34 pm
What is this Open Office and Word you speak of?

Pete :D
Title: Re: Pop-Up Video
Post by: SpriggsySpriggs on January 13, 2021, 12:02:50 am
If the video is mp4 then you can extract the audio with Audacity and then you can determine the length with SNDLEN.
Title: Re: Pop-Up Video
Post by: Pete on January 13, 2021, 12:33:18 am
I can't believe you had the audacity to recommend that!

Pete