0
\$\begingroup\$

I can play video which is there in my StreamingAssets folder. But is there a way in which I click a button and the same video gets played in the Windows Media Player. I researched a lot on this but could not find any solution.

This is the code for playing video normally,

   using UnityEngine;
using System.Collections;


public class VideoDemo : MonoBehaviour
{

public string filePath;
public string result;

void Start() {
    filePath = System.IO.Path.Combine (Application.streamingAssetsPath, "Demo.mp4");
    result = "";

}

void OnGUI() {
if(GUI.Button(new Rect(10,10,100,30),"Click Me"))
    {
        StartCoroutine(Example());
    }
}

IEnumerator Example ()
{
    if (filePath.Contains ("://")) {
        WWW www = new WWW (filePath);
        yield return www;
        result = www.text;

    } else
    {
        result = System.IO.File.ReadAllText (filePath);

    }
}

  }

Kindly share some ideas.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If you want to simply let windows open the default program for a file, this should do:

System.Diagnostics.Process.Start(@"file path");

If you want more control over what program opens and what arguments are passed, you can use this:

Process proc = new Process();
proc.StartInfo.FileName = @"C:\Program Files\... path to windows media player";
proc.StartInfo.Arguments = "\"" + file_name + "\"";
proc.Start();
\$\endgroup\$
3
  • \$\begingroup\$ Thank you. I will try this out.One more thing,considering the paths to WMP to be different for different users,how do I go about this? \$\endgroup\$ Commented Mar 11, 2014 at 7:15
  • \$\begingroup\$ It should be somewhere in the registry. This question comes close but is not exactly what you are looking for: stackoverflow.com/questions/19181676/… \$\endgroup\$
    – pek
    Commented Mar 11, 2014 at 7:22
  • \$\begingroup\$ I will look into it. Anyways, thanks for your time. \$\endgroup\$ Commented Mar 11, 2014 at 7:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .