I need to launch a media file from a URL from within my c# .NET application. Is there any way to do this natively in .NET? I don't need an embedded player, I just need the default player to launch. I have tried
System.Diagnostics.Process.Start("File URL");
but it launches the default browser and downloads the file, instead of attempting to play it in WMP/VLC/whatever the default media player is. Any ideas?
If you enter an URL it will be handled with the program registered to that URL format, in your case the default web browser.
What format are the media in? You can get associated program for an extension and then run that program with the url as parameter.
See:
Windows: List and Launch applications associated with an extension
So if your media is for example .MP3, then find the assoicated program for .MP3 (using the code in the link above) and pass the url as a parameter to that program.
Another way to handle this is to temporary download the file to the local file system and then run your
System.Diagnostics.Process.Start("Local File");
Then it should work as you expect.
Related
So i'm opening a standalone Unity app from a UWP store app. In my UWP app I use the unity WSA class to launch the custom uri I created.
Example:
In the register I created a custom uri called test:
In UWP app c# I use:
string uri = #"test:";
// Launch the URI
Launcher.LaunchUri(uri, true);
This works fine. The app launches. However if the app does not exist it pops up a dialogue to ask me with what I want to open it. Can I check this also while launching? So if the user has the app not installed I give the user feedback? I tried pretty much every class available for Unity and uri's etc. None of them do what I need. I had high hopes for a few, but all they did was tell me if the URI i entered are valid uri formats, rather then checking if it can actually open the app.
EDIT: Also, what's the difference between Launcher.launchURI and Application.OpenURL?
Application.OpenURL opens a url in the default browser, while Launcher.LaunchUri starts the default app associated with the specified URI.
And no, from the UWP app you just can’t query the system whether the URI is registered or not, there is no such API.
And LaunchUri just returns false if no app is launched, but at that time an error dialog is already prompted, so checking the return value of LaunchUri is not a solution either.
i just wanna upload afile from a fixed path, so i dont want browse button, I need just a TextBox(Path of my file some thing like c:/junk/upload) and and upload button.some thing like
[TextBox.Path][UploadButton]
or can i get the code in java applets or any other lanaguage?
For security reasons, a webpage loaded in a browser from internet cannot directly refer the local file system. You need a desktop application or plugin to achieve this.
no we can make using asp.net or java applets and yes what you said is right, security reasons! , but every applications has a sand box limits and thats include file handling as default , and we achived that. with out problem
I am having an issue opening a sound file I have in the "Files" folder. The application uses GET to obtain the file, so I can test this in the browser. However the exact name and location in the browser throws a 404. If I rename the file to the .txt extension, it opens just fine (downloads).
The original file is a .caf file that originates on an iPad and through a series of transactions, using a web service as the pivot point, gets downloaded to the web server. Then the file gets opened with an integrated QuickTime player. In this current scenerio the QuckTime player is unable to open the file because the server returns a 404 when looking for it.
It seems to me that when I open files that are not of some standard format (txt, jpg, png, mp3) then it does not work. I have a feeling that this this comes down to routing, but I am not sure what exactly I need to add to the routing to get this to work.
NOTE:
This works just fine when testing on my local machine; however, when moved into a test environment the application is unable to obtain the file.
You need to add the MIME type to IIS:
Multipurpose Internet Mail Extensions (MIME) types identify the types
of content that can be served to a browser or a mail client from a Web
server. When a browser requests content from a Web server, the browser
also requests the MIME type of that content. IIS returns this MIME
type as the Content_Type field in an HTTP header before returning the
content, so that the browser knows how to process or display that
content.
Since you have a non standard file type, you need to add it IIS
In my project i will be having an link like
Download
I want the users to download files of different types. The file will be in the root folder. When i am clicking on the link it is displaying an error. This is the plugin to install in the chrome. If the user download this link and open then it will automatically add to the chrome.
How can i do this.
The file is not even downloading.
This isn't a valid path:
~/hello world.crx
The ~ character is for use server-side to denote the root of the application. Client-side it has no meaning. The browser doesn't know what the root of the application is (or what the application is at all), it's just sending requests to resources at addresses. And it doesn't know what to do with that address.
You'll need to either use some server-side logic to translate that path into a browser-useable path, or manually make it a relative or absolute path.
If the ASP.NET MVC Framework isn't translating this for you then you're probably using a version that requires a little more manual work for it. Try something like:
Download
(Note: This assumes the use of the Razor view engine. If you're not using that then you'll want to use whatever your view engine equivalent is.)
What you need to do is set up a directory online, where you can host the file.
I also see that in your aref you don't want to type the full path so denote it with a /hello_world.crx, but make sure that you've set up a base href:
<base href="http://yourdomain.com/something/">
Try renaming the file to remove any spaces e.g. "hello_world.crx" and then change the name in the link code to match.
if a webpage and the downloadable file is in the same location
(i.e)
SampleFolder->Download.html
SampleFolder->hello world.crx
then try the below
download
If the webpage and the downloadable file in different location
(i.e)
SampleFolder->Download.html
SampleFolder->Downloads->hello world.crx
then try the below
download
The question says it all. Basically, I just want to know the alternative for this in WinRT:
Process.Start("http://www.google.com/");
In WinRT, you can use Windows.System.Launcher.LaunchUriAsync to launch the default app associated with the specified URI. For a web link, the default browser would be used.
MSDN: Launcher.LaunchUriAsync(Uri) | launchUriAsync(Uri) method
You can use Windows.System.Launcher to launch files and URL's...
Windows.System.Launcher.LaunchUriAsync(Uri) will launch a given Uri with the default application. If it's a link it will open with default web browser. You can use file:/// scheme to open an network resource, but not resources on the local file system.
Windows.System.Launcher.LaunchFileAsync(IStorageFile) will launch the default application for the given file.
Both that methods has an optional second parameter of type Windows.System.LauncherOptions that customizes the launch.