top of page
Search

Media Player Experiments

I will place the links to the videos pertaining to what I’m talking about after each segment. A customer asked when the screen saver was going to be ready for the PCs that were part of a technology order would be ready. That came as a bit of a surprise because it was something that the company I work for doesn't sell. In the end all they wanted was 3 or 4 video clips that would loop. What they wanted was basic and anyone with a mouse could make it happen. The customer didn't want their employees to do it. That lead me to think if there was a way to do this programmatically. With a little bit of research and patience I believe this can be done. Please understand I'm not doing this for the customer. This is for my own enlightenment.



Start Media Player and load a Video file using PowerShell. This is a continuation of the previous video. The initial piece was to go into a folder and list the contents in the terminal. That was done in PowerShell. This part is a little more specific. The goal is to start Media Player from the terminal either in Command Prompt or PowerShell. The first attempt succeeded in CMD opening just the Media Player. The script for me that worked is as follows. C:\Users\Username\AppData\Local\Microsoft\WindowsApps\MediaPlayer.exe It might be different depending on the version of Windows you are using. The next step to getting it to play did not go so well. That was when I found a PowerShell script that didn't focus on starting the application but on starting a process that started Media Player when player a designated video on full screen.


Example:

Start-Process "\\fileshare1\videos$\video.mp4" -WindowStyle Maximized 


You'll see the effect in the video.



Start a process that will start Media Player and play a designated video. Some people can figure out a complex problem in a few minutes. And the scary ones can do it in seconds. Then there is me. I don't have those superpowers. All I can do is try to break a problem down to smaller components and string them together. Sometimes it works right away. Other times not so groovy. In this project, I've been able to start Media Player in CMD. I was also able to run a video by typing the path to the file in the terminal. Now after a bit of reading and little trial and error between other tasks I found a PowerShell solution that is getting a little closer to my goal. Instead of trying to open Media Player directly I will start a process to play a designated video full screen. In Windows 10 it defaults to Media Player unless you install an alternative.



Building on our ability to start a process that will open media player and play mp4 files. Into the deep end of the pool. I am using this analogy to expresses how I feel about functions and variables. Most of my coding is direct and kept simple for multi-purpose use. This project has taken me closer to what I normally shy away from. It's not the end of the world or anything like that. It's just not my natural mindset. That would be "Get er dun". Have fun with bad grammar for a moment. Now in previous videos I've gone through this in bite sized pieces. This builds on our ability to start a process that will open media player a play an mp4 file. I've been doing some research on certain sites and found different CMD and PowerShell scripts that might be helpful. Here are two variants.


*** This script jumps to the last video and ends there. No video follows. ***


$files = Get-ChildItem *.mp4

for ($i = 0; $i -lt $files.Count; $i++) {

Start-Process -FilePath wmplayer.exe -ArgumentList $files[$i].FullName

}

Wait-Process -Name wmplayer



*** This is the closest to what I want to accomplish. What did happen is that it played a video and when I closed the window it started the next video. The same thing happened when the player closed a second time. ***


$files = Get-ChildItem *.mp4

foreach ($file in $files) {

Start-Process -FilePath wmplayer.exe -ArgumentList $file.FullName -Wait

}


Hopefully this is helpful to anyone else try to do something similar.



Attempting load videos back-to-back and failing. Since my last post it has been slow going with life interfering with my quest to figure this out. My research consisted of going to usual suspects for examples that I would experiment with. My thought process follows a basic structure of writing down a question. Find some code examples and test them. If it doesn't work the way I want I write down another and find more examples. Rinse and repeat. Last night I had a few uninterrupted hours to put things together. Some things worked while a lot more didn't. I won't put down what didn't work (that is in the video). At this point I am splitting hairs, but I want to get this done in just PowerShell. I am aware that I can use Python to open and close the media player, or to fill in the performance blanks that are not being done in PowerShell if I don't want to abandon the work I've done so far. I am going to continue with this between other projects. Here are some basic PowerShell scripts that did work. Try them out, if you like.


1) Assigning a variable to a path.

$firstMp4File = "C:\path\to\first.mp4"

$secondMp4File = "C:\path\to\second.mp4"


2) Starting Media Player in PowerShell directly.

Start-Process -FilePath wmplayer.exe


3) Using the variable in the Argument when starting a process.

Start-Process -FilePath wmplayer.exe -ArgumentList $firstMp4File


4) Closing Media Player in PowerShell.

Stop-Process -Name wmplayer



The End.

 
 
 

Kommentare


© 2023 by Sofia Franco. Proudly created with Wix.com.

bottom of page