## QMedia v1.5 | ## Using QMedia

Home | Playback | Internet delivery | Grabbing

Step 1 | Step 2 | Step 3

## Step 2: Opening a movie file or URL

QMedia can import media either from disk files or from Internet URLs. In either case the procedure is done transparently. In the case of URLs QuickTime provides internal support for the http, ftp, rtsp and file protocols.

Opening a movie from a disk file

QuickTime’s native format is the QuickTime movie. However, it recognizes a variety of foreign media file formats in-place as well as additional formats after conversion. In order to know whether a media file is readable by QuickTime, you first have to test it.

Note: If you are on Windows, do not forget that your media filenames must have their correct 3-letter extension. QuickTime reads extensions before deciding whether a file is readable or not.

QM_TestMovieFile lets QuickTime check if a media file is readable. If it is readable (either because it is a native QuickTime movie or because it is a foreign format that can be opened in-place), this command will return the movie type and it will indicate that there is no need for conversion. QM_TestMovieFile can either be passed the full pathname to a specific file or not. If you pass an empty pathname you will get the standard file selection dialog to select a file.

`` `C_LONGINT``($mustConvert;$error)` `C_TEXT``($filePath)` `C_STRING``(4;$movieType)` `$filePath:= "" ` display the selection dialog` `$error:= QM_TestMovieFile($filePath;$movieType;$mustConvert)` `If``($error = qm_NoErr)` `If` `($mustConvert = 1)` `` readable after conversion. Continued below.` `End if` `End if` ``

If QM_TestMovieFile indicates that conversion is needed, you will use QM_ConvertFileToMovieFile to convert the unreadable media file to a movie file, so that it can be opened.

`` `C_TEXT``($targetPath)` `$targetPath:= "" ` save as… dialog` `$error:= QM_ConvertFileToMovieFile($filePath;$targetPath)` `If` `($error = qm_NoErr)` `` $targetPath now points to the movie file` `` Create the movie instance from $targetPath here` `End if` ``

Finally, you need to get a reference to the movie by creating a movie instance. This is done with QM_NewMovieFromFile, a command you will be using a lot.

`` `C_LONGINT``($movieRef)` `$error:= QM_NewMovieFromFile($movieRef;$targetPath)` ``

Opening a movie from a URL

In the case you want to play back a movie from the Internet directly into QMedia's plug-in area, you only need to pass the URL to the command QM_NewMovieFromURL and you will get a movie reference you can work with.

The URL that you will pass should be fully qualified, i.e. it should also include the protocol. Examples of acceptable URLs are:

- `http://www.mydomain.com/media/birthday_movie.mov`
- `ftp://ftp.mydomain.com/public/birthday_movie.mov`
- `rtsp://216.178.7.117/~irh/irh.mov`

You can also use the file:// protocol that lets you access local files as if they were Internet URLs. This technique is equivalent to opening a disk file with your web browser, and it can be interesting because it allows you to write generic code irrespective of media source. Notice that, when you use QM_NewMovieFromURL you cannot test the validity of the media file in advance.