-
How can I double-click on a file and open it?
Hey, folks!
For a change of pace, I'm creating a media player which can play most video and audio formats (though it relies on external codecs to already be installed.
I want to add the functionality whereby if a user double-clicks on a supported file type from Windows Explorer, my custom media player would open and play it.
I have been able to make associations with particular file types (using the Power Object, and have been able to set up drag-and-drop functionality. But how would I able open a file from Windows Explorer directly?
Note that I am discussing opening a file from Windows Explorer--not MMF2's Developer tool.
Any ideas?...
Thank you very much in advance!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
You just said you had set up the file associations...and then you contradicted yourself by saying that double-clicking to open the files doesn't work? How did you set up the file associations?
EDIT: Er, I misunderstood, see Jacob's post and my post below.
-
Re: How can I double-click on a file and open it?
You will have to retrieve the command line to get the path of the file you opened with, and load that into your video or sound player.
-
Re: How can I double-click on a file and open it?
Don't forget that you can open multiple files in one program, and thus must check for that.
-
Re: How can I double-click on a file and open it?
Hey, folks! Thank you for the replies.
How do I access the command line to retrieve the path to selected files?
EDIT: I'm also stumped as to what the conditions for such an event would be. I'm not sure how to specify "when files outside of MMF2 are clicked."
Thank you again for your assistance! I really appreciate it!
RGBreality
-
Re: How can I double-click on a file and open it?
Use the Power System Object to get your app to open by default. That will only open it though, you'll also need to load the file when it opens.
The file that opened your program will be contained in the commandline; use the CommandLine$ expression to retrieve it. You'll need to manipulate it some to extract the filename from the other symbols it puts in, and it may be different for different ways you open the program (dragging the file onto the EXE vs. opening it from the file).
-
Re: How can I double-click on a file and open it?
Here is a quick example of how to get the files that were opened with your program.
http://mfa.aquadasoft.com/view/1308690494-ParseCommandLine
Just select a load of files and drag them onto the built EXE and watch it come up with the list.
Parsing the command line is tricky, as windows gives you some file paths with "" around them (if there are spaces in the URL), and it gives you some file paths without "" around them (if there are no spaces in them). Therefore this was a pretty tricky example to make!
-
Re: How can I double-click on a file and open it?
Hey, LB! Thank you very much for putting together this example file for me!
I am having a problem accessing it, though, as I don't have the "Internal object" object installed (nor can I find it on the FusionWiki Extension List). How can I get this extension?
Thank you again for all your help!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
Quote:
Originally Posted by RGBreality
I don't have the "Internal object" object
It's not good to paraphrase things; it's called the Internal List Object.
-
Re: How can I double-click on a file and open it?
Nifflas (I believe) made a widget that does this too :)
-
Re: How can I double-click on a file and open it?
Ah, I see that the Internal List Object is another excellent LB extension! Thank you for pointing me to it (and I see you updated it recently).
I was also able to find Nifflas' Widget. I'll have to study how both work.
However, I'm still a bit confused regarding how I use the Power System object as the condition by which a file is selected from Windows Explorer. Once I determine that condition, then I would use either LB's or Nifflas' work to import that file into the application.
So, could you spell out which condition I use in the Power System object to initiate this process?
Thank you all again for your continued assistance!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
The Power System Object has nothing to do with which files were opened with your application, it can just make it so that opening files with your application is the default thing when you double-click them. Windows then launches your application and passes the file paths in the command line, which, with my example or Nifflas' widget, you can get the file paths and do whatever you want with them.
-
Re: How can I double-click on a file and open it?
Hey, LB! Thank you for your continual advice! I really appreciate it!
I have made progress in this endeavor... I found that using the YASO object seemed to work better in creating the file associations. However, it still doesn't quite function correctly. Here is my status with it so far...
I created the following event:
--Start of Frame
--YASO Object: A global association for "Play with Media Player" doesn't exist
+ YASO object action: Associate file path to player with "Play with Media Player"
+ YASO object action: Associate file extension "mp3" to file path to media player
+ YASO object action: (Repeat the last action for each file extension type the media play is to support)
Using this event, I find that it doesn't actually change the default media player for any of the file extensions I list; however, it does add the "Play with Media Player" text when right-clicking on a file. If I select the "Play with Media Player" option, I get a Windows dialog box asking which program I want to open the file with (it seems Windows still doesn't know the file association).
Yet, if I browse to the media player and select it to open, the file does properly load into the media player, display into the play list, and can be properly played. (So I greatly appreciate your help with getting me this far!)
So, I seem to be incorrectly specifying file associations. I found that if I used the Power System object to create such associations, the player would crash when loading (and I wouldn't see the "Play with Media Player" right-click option).
After that long-winded explanation, do you have any idea what I may be doing wrong?
Thank you again!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
[size:8pt]I modified the example MFA from before so that it associates itself with the .specialtxt format: (make sure to build it first)
http://mfa.aquadasoft.com/view/1309211261-FileAssociations_Opening_CLParsing
And it seems you are right (though it's not crashing); it seems that windows isn't passing the information about which file was opened, as it is not present in the command line. I'm not sure if this is the PSO or not, maybe Jaffob can shed some light...[/size]
EDIT: Jaffob & SortaCore told me in the chat that the fourth parameter for adding an association (the command line one) needs to have a %1 in it to specify where you want Windows to pass the path parameter. Here is the fixed example:
http://mfa.aquadasoft.com/view/1309213902-FileAssociations_Opening_CLParsing
-
Re: How can I double-click on a file and open it?
Hey, LB! Thank you again for your assistance with this. And a big thanks to Jaffob and SortaCore for their clarification with the Power System object.
I'm afraid that when I use the Power System object for file extension creation and/or file association, it crashes my application when it starts. To minimize my human error, I copied and pasted the Power System object events from your sample file to my application, and changed the extension and application association information.
I've uploaded my MFA file here. Unfortunately my MFA file is not commented, so it's a big mess. However, the file extension creation/file association events are at the beginning (with the Start of Frame events), so there's no need to dig for it. The MFA file is here:
View MFA
As always, thank you very much for your continued assistance with this!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
Why do you have the Start of Frame-> Add Associations in the global events?? You already have the correct events in your second frame...
-
Re: How can I double-click on a file and open it?
Hey, LB!
I must be confused between the different Power System object actions...
I had thought that the "extension XYZ does not exist" condition represented that the local computer did not know of XYZ extension; its corresponding action creates an association with the media player.
However, I thought the "extension XYZ does not have association with the media player" represented that the extension was known on the local computer, but that extension was associated with a different application; its corresponding action creates the association with the media player.
In short, I thought I needed both condition/action for each pertinent file extension.
Am I misunderstanding how this should be used?
(It occurs to me that I could make this run faster if on the Start of Frame condition I create a Fastloop which does all the file association actions, rather than having them done separately during the Start of Frame.)
Thank you again!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
You're correct; that's not what you did wrong. Open the global events and delete that Start of Frame event - it's just messing stuff up. Also, try resetting and/or deleting the extensions and associations and allow your app to recreate them - it could be that something weird happened while you were making the application.
-
Re: How can I double-click on a file and open it?
Ah, I see... Thanks for the good tip.
I did remove all the file extension type associations (manually) that this application adjusts. Unfortunately, it still crashes at run-time.
Are there any other objects which manipulate file associations (such as the YASO)? I did try using the YASO after the Power System object was crashing, but it seemed that the YASO object wasn't making system changes. What would be the event/action the YASO object would use? Or would you recommend another object?
Thank you again for your great advice and guidance!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
My widget won't be helpful since it only returns the first file rather than the whole list. If you need to load multiple files at once into a playlist, LB's example is better.
-
Re: How can I double-click on a file and open it?
I'm still looking at your MFA, and I haven't found why it crashes, nor have I been able to reproduce the crash at all. I do have to wonder why you're making inefficient use of extensions and objects - for instance, you have about 12 to 13 Cursor object extensions when you'd only ever need to reuse one to change the cursor. Also, you seem to be destroying the Advanced Tray object in global events, and it could still *possibly* be used. You also have two instances of the same window control object...I haven't even finished analyzing it all. Thankfully you only have a few objects with behaviors...
If you could try and see which event causes the crash (eg write to an INI file "Event #1" etc for each start of frame event you have and see where it stops writing) then that would help me to see what it could be, because as I said I can't reproduce the crash.
-
Re: How can I double-click on a file and open it?
Hey, LB! You are one awesome guy for helping me out like this!
And you're also awesome for giving me some best-practices tips. Despite that I have been using MMF2 for about a year now, I'm sure I've taught myself some bad practices. It's good to be told better ways of doing things. I've already cleaned up the use of all the Cursor objects to use only one Cursor object.
I can tell you which event/actions cause the application to crash: it is the Power System object's event "if an extension is not associated with the application" condition (and/or its accompanying action) that causes the application to crash. When I remove those events, the application loads properly.
I have uploaded a new iteration of this MFA that incorporates your Command Line events/actions using your Internal List object. I haven't been able to test it properly, since I don't have the file associations set up properly yet, but I thought I would show it to you and see if I set that up properly. These events are at the beginning of the project (near the "Start of Frame" events).
View MFA
As always, I deeply appreciate the effort you have offered to help me with this. You definitely help noobies like myself learn this product better!
RGBreality
-
Re: How can I double-click on a file and open it?
In that MFA you still haven't removed that start of frame action from the global events.
As for your implementation, it looks fine, just FYI you don't need the "Full Command Line" alterable string (it was just in the example for display purposes and was not actually used)
-
Re: How can I double-click on a file and open it?
Hey, LB! Thank you for looking at the implementation of your Command Line import function... That's one less thing to worry about! I think I also appropriately removed the Start of Frame action you had mentioned.
I'm still working on the Power System object's file association problem, though... I tried placing the file association events into the Custom Window's Fastloops (one for when the window is initially opened, the other when the application is subsequently opened). Yet, the application crashes upon run-time (it doesn't even fully load the application).
So, you feel that there's nothing in the implementation which might be causes this crash? If that is the case, could I use a different object (such as the YASO) to perform the same functionality?
Just to confirm that I didn't mess something up when setting up the Power System object events, I've uploaded the latest iteration of the MFA file here:
View MFA
Thank you again for your time with this!
Most appreciatively...
RGBreality
-
Re: How can I double-click on a file and open it?
I'm still unable to reproduce any crash even after mutilating it. :( I'm not sure what else you can do - if you can find a YASO widget and figure out how its code works (I haven't) then you can see if YASO works for this. I'm at the limit for solving this problem...
Just a recommendation, you shouldn't be setting file type descriptions to things like "Open such and such with My Media Player" because it doesn't make sense - it's like instead of PNG files being "Portable Network Graphics" they'd be "Open PNG files with MS Paint" which doesn't make sense. Similarly with the associations, it doesn't make sense to right click on a file and see "My Media Player" instead of "Open" or "Play".
-
Re: How can I double-click on a file and open it?
I can't reproduce the crash either. Try some simple beta testing; create a new application with only the Power System Object in it and see if you can get it to crash. If not, you probably have some extra code tucked away somewhere in your application.
Does your computer/user account have full access to the registry? What version of Windows are you running?
EDIT: Also, about file associations. Unless you are registering new file types (e.g. MMF2 registers the new .MFA extension), all associations should be optional. Ask the user if they want the associations to be created, and if so, then you do it. When I ran your application it associated your application with all of my music and video file types; your users may not want this.
-
Re: How can I double-click on a file and open it?
Great work Jaffob! :)
Found a small issue: If I close the "Categorize Extension" window from Extension Manager the window elements stay disabled.
-
Re: How can I double-click on a file and open it?
Thanks a lot for the bug report, this will be fixed in the next release.
You do seem to have landed your post in an entirely separate thread however. :laugh:
-
Re: How can I double-click on a file and open it?
LOL You're right. This happens if you read more than one threads at once... :grin:
-
Re: How can I double-click on a file and open it?
Thank you for all the feedback, guys--especially for LB's help and effort in this!
I will keep playing with this and see if I can get it working. If I have any other questions, I'll post a new thread.
Definitely most appreciatively...
RGBreality