playing_20a_20media_20file_20using_20direct_20show
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
playing_20a_20media_20file_20using_20direct_20show [2018/03/31 13:19] – external edit 127.0.0.1 | playing_20a_20media_20file_20using_20direct_20show [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Playing a media file using Direct Show===== | =====Playing a media file using Direct Show===== | ||
- | //by Richard Russell, December 2007//\\ \\ Windows provides several methods for playing audio and video files. One of the simplest is the Media Control Interface (MCI) which is used by //BBC BASIC for Windows// to play MIDI files and is also the basis of the **PLAYER.BBC** media player application which can be found [[http:// | + | //by Richard Russell, December 2007//\\ \\ Windows provides several methods for playing audio and video files. One of the simplest is the Media Control Interface (MCI) which is used by //BBC BASIC for Windows// to play MIDI files and is also the basis of the **PLAYER.BBC** media player application which can be found [[http:// |
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
Line 8: | Line 10: | ||
SYS " | SYS " | ||
SYS `CoInitialize`, | SYS `CoInitialize`, | ||
- | To ensure the necessary 'clean up' operations are carried out on exit the program should include **ON ERROR** and **ON CLOSE** statements:\\ \\ | + | </ |
+ | |||
+ | To ensure the necessary 'clean up' operations are carried out on exit the program should include **ON ERROR** and **ON CLOSE** statements: | ||
+ | |||
+ | <code bb4w> | ||
ON ERROR PROCcleanup : SYS " | ON ERROR PROCcleanup : SYS " | ||
ON CLOSE PROCcleanup : QUIT | ON CLOSE PROCcleanup : QUIT | ||
- | The next step is to // | + | </ |
+ | |||
+ | The next step is to // | ||
+ | |||
+ | <code bb4w> | ||
CLSID_FilterGraph% = FNguid(" | CLSID_FilterGraph% = FNguid(" | ||
IID_IGraphBuilder% = FNguid(" | IID_IGraphBuilder% = FNguid(" | ||
Line 19: | Line 29: | ||
\ | \ | ||
IF hr% THEN ERROR 100, "Could not create filter graph manager" | IF hr% THEN ERROR 100, "Could not create filter graph manager" | ||
- | Once the filter graph manager COM object is instantiated we can use it to create two other DirectShow objects, firstly a **media control object**:\\ \\ | + | </ |
+ | |||
+ | Once the filter graph manager COM object is instantiated we can use it to create two other DirectShow objects, firstly a **media control object**: | ||
+ | |||
+ | <code bb4w> | ||
IID_IMediaControl% = FNguid(" | IID_IMediaControl% = FNguid(" | ||
SYS !(!m_graphBuilder%), | SYS !(!m_graphBuilder%), | ||
IF hr% THEN ERROR 100, "Could not instantiate media control object" | IF hr% THEN ERROR 100, "Could not instantiate media control object" | ||
- | and secondly a **media event object**:\\ \\ | + | </ |
+ | |||
+ | and secondly a **media event object**: | ||
+ | |||
+ | <code bb4w> | ||
IID_IMediaEvent% = FNguid(" | IID_IMediaEvent% = FNguid(" | ||
SYS !(!m_graphBuilder%), | SYS !(!m_graphBuilder%), | ||
IF hr% THEN ERROR 100, "Could not instantiate media event object" | IF hr% THEN ERROR 100, "Could not instantiate media event object" | ||
- | If the above code succeeded we now have all three Direct Show objects required to handle streamed audio or video playback.\\ \\ To play a file we need to create a **filter graph**:\\ \\ | + | </ |
+ | |||
+ | If the above code succeeded we now have all three Direct Show objects required to handle streamed audio or video playback.\\ \\ To play a file we need to create a **filter graph**: | ||
+ | |||
+ | <code bb4w> | ||
SYS !(!m_mediaControl%+44), | SYS !(!m_mediaControl%+44), | ||
IF hr% THEN ERROR 100, "Could not render file " | IF hr% THEN ERROR 100, "Could not render file " | ||
- | Here **mediafile$** should be a fully-qualified path and filename of the file to be played.\\ \\ Now everything is ready to play the file:\\ \\ | + | </ |
+ | |||
+ | Here **mediafile$** should be a fully-qualified path and filename of the file to be played.\\ \\ Now everything is ready to play the file: | ||
+ | |||
+ | <code bb4w> | ||
SYS !(!m_mediaControl%+28), | SYS !(!m_mediaControl%+28), | ||
Line 40: | Line 66: | ||
SYS !(!m_mediaEvent%+36), | SYS !(!m_mediaEvent%+36), | ||
UNTIL pEvCode% | UNTIL pEvCode% | ||
- | You can carry out other operations while the file is playing by including them in the above waiting loop.\\ \\ To play another file, you should release the three objects as in **PROCcleanup** below (but //not// call **CoUninitialize**) and then instantiate the three objects again starting with the filter graph manager. It is preferable to call **CoInitialize** just once at the very start of the program, and **CoUninitialize** just once on exit.\\ \\ Before exiting the program you should call the 'clean up' routine: | + | </ |
+ | |||
+ | You can carry out other operations while the file is playing by including them in the above waiting loop.\\ \\ To play another file, you should release the three objects as in **PROCcleanup** below (but //not// call **CoUninitialize**) and then instantiate the three objects again starting with the filter graph manager. It is preferable to call **CoInitialize** just once at the very start of the program, and **CoUninitialize** just once on exit.\\ \\ Before exiting the program you should call the 'clean up' routine: | ||
+ | |||
+ | <code bb4w> | ||
PROCcleanup | PROCcleanup | ||
QUIT | QUIT | ||
Line 50: | Line 80: | ||
SYS `CoUninitialize` | SYS `CoUninitialize` | ||
ENDPROC | ENDPROC | ||
- | Should you wish to pause or stop playback prematurely you can do so using the following code segments:\\ \\ | + | </ |
+ | |||
+ | Should you wish to pause or stop playback prematurely you can do so using the following code segments: | ||
+ | |||
+ | <code bb4w> | ||
REM Pause playback: | REM Pause playback: | ||
SYS !(!m_mediaControl%+32), | SYS !(!m_mediaControl%+32), | ||
Line 56: | Line 90: | ||
REM Stop playback: | REM Stop playback: | ||
SYS !(!m_mediaControl%+36), | SYS !(!m_mediaControl%+36), | ||
- | Finally here are the functions **FNwide** and **FNguid** used by the above code:\\ \\ | + | </ |
+ | |||
+ | Finally here are the functions **FNwide** and **FNguid** used by the above code: | ||
+ | |||
+ | <code bb4w> | ||
DEF FNwide(A$) | DEF FNwide(A$) | ||
LOCAL M$ | LOCAL M$ | ||
Line 69: | Line 107: | ||
SYS `CLSIDFromString`, | SYS `CLSIDFromString`, | ||
= C% | = C% | ||
+ | </ | ||
+ | |||
==== Fullscreen output ==== | ==== Fullscreen output ==== | ||
- | \\ | + | |
+ | To display a video file fullscreen, add the following code immediately before the call to **Run()**: | ||
+ | |||
+ | <code bb4w> | ||
REM Instantiate a video window object: | REM Instantiate a video window object: | ||
IID_IVideoWindow% = FNguid(" | IID_IVideoWindow% = FNguid(" | ||
Line 95: | Line 138: | ||
SYS IVideoWindow.put_FullScreenMode%, | SYS IVideoWindow.put_FullScreenMode%, | ||
IF hr% THEN ERROR 100, "Could not set fullscreen mode" | IF hr% THEN ERROR 100, "Could not set fullscreen mode" | ||
- | To close the fullscreen window, use the following code:\\ \\ | + | </ |
+ | |||
+ | To close the fullscreen window, use the following code: | ||
+ | |||
+ | <code bb4w> | ||
WM_CLOSE = &10 | WM_CLOSE = &10 | ||
SYS " | SYS " | ||
IF hamw% SYS " | IF hamw% SYS " | ||
+ | </ | ||
+ | |||
==== Windowed output ==== | ==== Windowed output ==== | ||
- | \\ | + | |
+ | To display a video file in a window (whose size and position you can specify), add the following code immediately before the call to **Run()**: | ||
+ | |||
+ | <code bb4w> | ||
REM Instantiate a video window object: | REM Instantiate a video window object: | ||
IID_IVideoWindow% = FNguid(" | IID_IVideoWindow% = FNguid(" | ||
Line 135: | Line 187: | ||
SYS IVideoWindow.SetWindowPosition%, | SYS IVideoWindow.SetWindowPosition%, | ||
IF hr% THEN ERROR 100, "Could not set window rect" | IF hr% THEN ERROR 100, "Could not set window rect" | ||
- | To close the video window, use the following code:\\ \\ | + | </ |
+ | |||
+ | To close the video window, use the following code: | ||
+ | |||
+ | <code bb4w> | ||
WM_CLOSE = &10 | WM_CLOSE = &10 | ||
SYS " | SYS " | ||
IF hamw% SYS " | IF hamw% SYS " | ||
+ | </ |
playing_20a_20media_20file_20using_20direct_20show.1522502373.txt.gz · Last modified: 2024/01/05 00:17 (external edit)