Jump to content

Recommended Posts

Posted

hey guys,

I've been using autoit for a long time now and have always found solutions to problems on these forums. This time however I couldn't find any so this is my first post.

Basically I am trying to write a script which is passed a value when it is run, in this case the name of a video file. The script then opens windows media player, plays the video and then when I press escape it exits. This is what I've got so far.

If $CmdLine[1] Then
HotKeySet("{ESCAPE}", "_Escape")
Run("C:\Program Files\Windows Media Player\wmplayer.exe" & " /play" & " /fullscreen" & $CmdLine[1])
EndIf

While 1
    Sleep(1000)
WEnd


Func _Escape()
ProcessClose("wmplayer.exe")
Exit
EndFunc

I was unsure about the cmdline code but that is how I had found it used on the forums and in the help file. When I run this code and pass it a file to play i.e. autoit.exe video.avi it opens windows media player but it doesn't play anything. Obviously I'm doing something wrong but I can't seem to work out what it is.

So... there is it, remember its my first post so be kind, thanks.

Posted

If you're going to do this:

If $CmdLine[1] Then

You must have already checked that $CmdLine[1] exists, or your script will crash when called with no parameters.

Better to test:

If $CmdLine[0] AND $CmdLine[1] <> "" Then

This will not crash under those circumstances.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...