PDA

View Full Version : Custom File Types/Open In App



RizlaUK
03-28-2007, 04:39 AM
Hey Guys,

after i posted my last app i received a few requests for the code to make the file open in the app, so here it is

in this example i used a .mxt (so it dosent mess up your file association)

build the app and run it once to set the association, then rename a compatible audio file and .mxt and double click it and it will open in the example app

I take no credit for this code, it is code i got from a few posts in the forum, all i did was combine the code into a working example

Have Fun ;)

medina07
04-27-2007, 01:24 PM
Very good work, is of a lot of utility, thank you to share it with us.:yes :yes

Desrat
04-27-2007, 03:33 PM
thats a very useful example to have..thanks RizlaUk

AudioSam
04-27-2007, 11:54 PM
Good Work RizlaUK.
It works, ...How you do that?
lol
Thank You
AudioSam

Ham
04-28-2007, 03:48 AM
Really nice RizlaUK:yes :yes

RizlaUK
04-28-2007, 07:52 AM
hey, wow, 4 weeks later and my post appears, i had given up on this one, guess the powers that be was just to busy (working on AMS 7 with any luck ;) )

medina07
04-28-2007, 01:40 PM
I am trying to load the file with extension (.mp3) to a ListBox and from this to the Media Player, but I get an error (MediaPlayer doesn't support the following extension: (.) ).
But when I load the file (.mp3) directly to MediaPlayer everything it works marvelously - I have changed "CHANNEL_NARRATION" for MediaPlayer plugin-
Where is the error?


check to see if any commandline arg was passed to the app
if _CommandLineArgs[1] then
if String.Left(_CommandLineArgs[1], 3) ~= "SFX" then
YourCustomFile = _CommandLineArgs[1]
sPath = String.SplitPath(YourCustomFile);
Input.SetText("Input1", sPath.Filename);

-- Add the item to the ListBox
ListBox.AddItem("Playlist", String.SplitPath(YourCustomFile).Filename, sPath.Filename);
-- Select item from ListBox
ListBox.SelectItem("Playlist", 1);

end
end :rolleyes :rolleyes

medina07
04-28-2007, 02:02 PM
My app loads the name of the song from the ListBox but doesn't run it.

RizlaUK
04-28-2007, 02:08 PM
i assume you are loading the file into the mp plugin via the listbox "Data" field

if that is the case you are loading just the filename, which is useless, you need to send the full path to it

and you are splitting the path twice (waist of code)

try this:



--check to see if any commandline arg was passed to the app
if _CommandLineArgs[1] then
if String.Left(_CommandLineArgs[1], 3) ~= "SFX" then
YourCustomFile = _CommandLineArgs[1]
sPath = String.SplitPath(YourCustomFile);
Input.SetText( "Input1", sPath.Filename);

-- Add the item to the ListBox
ListBox.AddItem( "Playlist", sPath.Filename, YourCustomFile);
-- Select item from ListBox
ListBox.SelectItem( "Playlist", 1);

end
end

output enhanced with AMS Code Pretty (http://www.indigorose.com/forums/showthread.php?t=19409)

mz241508
04-28-2007, 02:09 PM
Try this code:

--check to see if any commandline arg was passed to the app
if _CommandLineArgs[1] then
if String.Left(_CommandLineArgs[1], 3) ~= "SFX" then
YourCustomFile = _CommandLineArgs[1]
sPath = String.SplitPath(YourCustomFile);
Input.SetText("Input1", sPath.Filename);

-- Add the item to the ListBox
ListBox.AddItem("Playlist", sPath.Filename, YourCustomFile);
-- Select item from ListBox
ListBox.SelectItem("Playlist", 1);
end
end
LOL, looks like RizlaUK beat me to it! :p

RizlaUK
04-28-2007, 02:12 PM
lol....beat ya by 30 seconds ;)

medina07
04-28-2007, 02:46 PM
Thank you RizlaUK and mz241508 now everything works perfectly.:yes :yes

medina07
04-28-2007, 03:21 PM
This way I can initialize the file automatically from the ListBox


--check to see if any commandline arg was passed to the app
if _CommandLineArgs[1] then
if String.Left(_CommandLineArgs[1], 3) ~= "SFX" then
YourCustomFile = _CommandLineArgs[1]
sPath = String.SplitPath(YourCustomFile);
Input.SetText( "Input1", sPath.Filename);

-- Add the item to the ListBox
ListBox.AddItem( "Playlist", sPath.Filename, YourCustomFile);
-- Select item from ListBox
ListBox.SelectItem( "Playlist", 1);
-- Get the selected item(s) from the ListBox
Selected = ListBox.GetSelected("Playlist");
-- Ensure that there was an item selected
if Selected then
-- Get the path to the selected file (stored in the item's 'data')
FilePath = ListBox.GetItemData("Playlist", Selected[1]);
-- load the file
MediaPlayer.Load("Media", FilePath);
-- play the file
MediaPlayer.Play("Media");
-- start the timer
Page.StartTimer(500);
-- set as playing
Playing = true
-- set as not paused
Paused = false
-- set as loaded
Loaded = true
-- set the total time
Label.SetText("Total", Clock(MediaPlayer.GetLength("Media")));
end
end
end:D :D

SiNisTer
05-07-2007, 11:55 PM
Hey guys I tried the some of the codes & it works perfectly until you try to open multiple mp3 files - then it starts to open several instances of the player (the application) to load each file:lol
I hope some one can try to update this part of the codes...It'll be really useful...

BTW is there also a way to read the data in a saved .m3u playlist and load this into the listbox when I double click it considering the my app is set as the default Application for the file?

Desolator
05-08-2007, 12:30 AM
Yes. Detect the extension and load the playlist.

Imagine Programming
05-08-2007, 04:01 PM
RizlaUK, nice work with the open with app... it works fine... only one nasty thing won't work when i build your example program.... the icon...

i just cant get it right...

i click the mxt file and it opens it with your example program... but i see a unreconized windows icon...

what should i do?

greets... Crusiatus Black

Mert Özsoy
06-21-2012, 11:03 PM
I do not know English. I need help. This APZ file worked for me. Could not figure out where the error I'm doing.

Global Functions;

function CreateFileAssociation(strApplicationPath, strFileExtension, strAppShortName, strIconFile)
Registry.SetValue(HKEY_CLASSES_ROOT,strFileExtensi on,"",strAppShortName);
local strCommandLine = "\""..strApplicationPath.."\" \"%1\"";
Registry.SetValue(HKEY_CLASSES_ROOT, strAppShortName.."\\shell\\open\\command", "", strCommandLine);
if(File.DoesExist(strIconFile))then
local strApp83path = File.GetShortName(strIconFile);
Registry.SetValue(HKEY_CLASSES_ROOT, strAppShortName.."\\DefaultIcon", "", strApp83path..",0");
end
end
On Preload;

local strApplication = "C:\\Program Files\\Windows Media Player\\wmplayer.exe"
CreateFileAssociation(strApplication, ".mp3", "Müzik Dosyası", _SourceFolder.."\\AutoPlay\\Icons\\48x48x32.ico") ;
On Show;


-- check to see if any commandline arg was passed to the app
if _CommandLineArgs[1] then
if String.Left(_CommandLineArgs[1], 3) ~= "SFX" then
YourCustomFile = _CommandLineArgs[1]
sPath = String.SplitPath(YourCustomFile);
Input.SetText("Input1", sPath.Filename);

Audio.Load(CHANNEL_USER1, YourCustomFile, true, false);

end
end

Page.StartTimer(100);