var filePath = "/Volumes/StorageHD/Audio/iTunes Music/Air/Talkie Walkie/01 Venus.mp3"; var p = new Process(); p.StartInfo.FileName = "/Applications/VLC.app/Contents/MacOS/VLC"; p.StartInfo.Arguments= filePath; p.Start(); Console.ReadKey();
This code launches VLC, but each space in the file path is parsed as a new file name, so VLC attempts (and fails) to play iTunes, Talkie, Walkie, 01 and Venus.mp3.
My first attempt to fix this was to escape the file path as a Unix file path i.e.
"/Volumes/StorageHD/Audio/iTunes\ Music/Air/Talkie\ Walkie/01\ Venus.mp3"
which is what I'd use if I were trying to do something similar from the shell:
$ vlc /Volumes/StorageHD/Audio/iTunes\ Music/Air/Talkie\ Walkie/01\ Venus.mp3
This was not the correct option ;) - my little console application threw a lot of stack-tracey goodness, but the main point was "Unrecognized escape sequence".
Instead I needed to escape the path as I would on windows, with the path with spaces in wrapped in double quotes:
var filePath = "\"/Volumes/StorageHD/Audio/iTunes Music/Air/Talkie Walkie/01 Venus.mp3\"";
Notice the escape character ("\") before the wrapping quote.
The final full code is available as a gist https://gist.github.com/StephenFriend/593aa94366cd4733be46
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var filePath = "\"/Volumes/StorageHD/Audio/iTunes Music/Air/Talkie Walkie/01 Venus.mp3\""; | |
var p = new Process(); | |
p.StartInfo.FileName = "/Applications/VLC.app/Contents/MacOS/VLC"; | |
p.StartInfo.Arguments = filePath; | |
p.Start(); | |
Console.ReadKey(); | |
} | |
} |