Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to get QMediaPlayer to play a network file on a Mac?
I'm working on an application that will use a QMediaPlayer widget, and which will need to work on both PC and Mac.
I have a series of UNC paths to video files that are stored on a server (the fact these are stored in Windows-style UNC paths is a legacy thing and can't be changed). They are of the format "\188.8.131.52\path\movie.mp4". I need to be able to get QMediaPlayer to open these files and play them from the server.
On Windows, there's no problem- QMediaPlayer is playing the media files really nicely indeed, I'm very happy.
However on Mac, I am hitting a "Failed to load media" message no matter what I try. I've tried various combinations of Samba prefixes, QUrl's setScheme method, and so on- but any path that involves an IP address is always hitting "Failed to load media", every time, with any path of a format like "smb://11.22.33..44/path/movie.mp4".
If I use a QFileDialog and browse manually to the file, then the file will definitely play on a Mac. The QUrl then reports as "file:///Volumes/path/movie.mp4" and it plays fine. However I don't know how to translate a "smb://" path into a "file:///Volumes/" path, and as it stands I don't think it can be assumed that the drive will already be mounted.
Please can someone give me a pointer on how to get a QMediaPlayer playing a remote file on a Mac?
Denni 0 Banned last edited by
Okay if QFileDialog returns the proper reference to the object within the Mac environment then I would suggest either figuring out how/why the QFileDialog does this and duplicate it -- or -- sub-class QFileDialog in such a way as to use it just retrieve the file.
That seems like the simplest approach to solving the situation and you can make that even semi-generic regardless of which of those 2 methods you choose -- and as such and use that with whatever OS you are working with
The QFileDialog is generating a path which QMediaPlayer will then read from, but only if I manually navigate to the file using a QFileDialog front-end and tell it exactly where it is.
My problem is simpler and more fundamental than I first implied, and involves trying to convert a string "\184.108.40.206\path\movie.mp4" into a valid MacOS path that any function (e.g. shutil.copyfile) will accept.
Hi and welcome to devnet,
Where do you get that string from ? Usually on *nix OSs all paths are using forward slashes.
In any case, you have QDir::toNativeSeparators to get a path which can be passed to function expecting such a string.
Thanks for the response.
The paths are from an existing piece of software which has stored the paths of lots of files as strings in a database. That existing software has been Windows-only for years so until now there was no issue with using UNC paths, but this new code I'm working on needs to be both Windows- and Mac-friendly, hence the UNC paths suddenly being a problem.
In order to move something forward I'm now working on automatically mounting the required servers when needed. I don't know whether this is the only way to do it on a Mac for QMediaPlayer use, or whether this is a temporary workaround and there may be a better solution I haven't found yet.
Denni 0 Banned last edited by Denni 0
For full cross compatiblity you might want to consider altering the data from "\folder\folder\file.ext" to "/folder/folder/file.ext" as Windows will accept forward-slashes as well as back-slashes while many other OSs only accept forward-slashes