Click here to Skip to main content
15,066,193 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:

I making a music player based on the libvlc library.
I use the DLLs libcore and libvlc, and the plugins from the VLC player installed on my computer.
In debug mode, the player plays music and video as i should.
But in release mode, i wont play anything. Why is this?

The plugins are located in the resource folder beneath the project folder,
and this code is used to get to them (wherever the project folder is located, because im going to deliver my project on a CD):

String path = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
path = path.Replace("\\bin\\x86\\Debug", "\\Resources");
path = "--plugin-path=" + path;
instance = new VlcInstance(new String[] { path });

And the two DDLs (libcore and libvlc) are located in this folder:

C:\Users\Trond\Documents\Hiof\6. Semester\dotNET\VLCMediaPlayer\VLCMediaPlayer\bin\x86\Debug

Has it something to do with this?

Best regards, Trond :)
Sergey Alexandrovich Kryukov 26-Apr-12 12:10pm
Isn't the problem obvious? The path depends on configuration...
Sergey Alexandrovich Kryukov 26-Apr-12 12:12pm
Reason for my vote of 2
The problem is right before the reader eyes. If this is not clear, OP should have used debugger before asking questions like that.

1 solution

There are no cases when a hard-coded file path, absolute or relative, can be useful. Exclusions can be made for purely experimental parts of the code, during development only. Get rid of paths and the problem will go.

What I can see is: you are trying to use the directory where your executable program is. Trying to hard-code it will never help. What you need is to calculate the location of a main executable module of your entry assembly. This is how:

string exeLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
string exeDirectory = System.IO.Path.GetDirectoryName(exeLocation);

This way if very universal, tolerant to the way the application is hosted and all other detail. There are other methods which are not that accurate.

Another alternative is using resources embedded in an executable file, such as *.resx resources.

trondwee 26-Apr-12 12:45pm
Like this?

string pathLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
string pathDirectory = System.IO.Path.GetDirectoryName(pathLocation);

pathDirectory = pathDirectory.Replace("\\bin\\x86\\Debug", "\\Resources");

pathDirectory = "--plugin-path=" + pathDirectory;
instance = new VlcInstance(new String[] { pathDirectory });

My player still wont play in release mode. I cant get rid of the path, becuse the player need those plugins.
Sergey Alexandrovich Kryukov 26-Apr-12 14:50pm
No! \bin\x86\Debug should not be mentioned in the project, ever.
What is not obvious? I told you exactly what to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900