Playing a variety of audio and video files using DirectX is relatively simple because NeoDX insulates you from the difficult-to-learn DirectX interface. The steps below demonstrate how to create a basic media player with NeoDX:
We recommend that you start with a new VisualNEO for Windows publication.
1. First you will need to use VisualNEO for Windows's Rectangle tool to define the location on the screen where you want the video to appear. To do this, simply select the Rectangle tool from VisualNEO for Windows's Tool Palette and draw a box on your publication. When your publication runs, the rectangle will be replaced by the DirectX media player, so make sure that it is large enough to display the video file you have in mind. After creating the rectangle, your screen should look like this:
2. Select Page Properties from VisualNEO for Windows's Page menu.
3. Click the Actions icon on the left side of the Page Properties dialog.
4. Click the Insert Action button.
5. Locate and select the NeoDX category among the icons on the left side of the Action Selector. If you don't see an icon for DirectX, then you have not properly installed the NeoDX plug-in. See Install Plug-Ins in VisualNEO for Windows's Options menu.
6. After selecting the DirectX icon, select dxCreate from the right side of the screen. The following dialog box will appear:
7. Type the name of the Rectangle object you created in step one in the Name of Rectangle Object to Attach DirectX Media Player to field. If you don't remember the name of the rectangle you can click the small gear icon to the right of the field to select it from a list.
You can leave the Rectangle field blank to create an invisible media player. This can be handy if you only want to play audio or music files that do not need to display anything on the screen. However, for this example, you should enter the name of the rectangle.
8. In the Variable to Store Media Player ID field, enter the name of a variable that NeoDX should use to store the media player's unique identification number. For this example, enter the following variable name:
This is very important. Since NeoDX allows you to create multiple media players at the same time, you will use the number stored in the variable to identify this media player to other NeoDX actions. More on this later.
9. Click OK to assign the dxCreate action to the page enter action, then click OK again to save the changes to the Page Properties.
10. Next, create a Push Button object to the right of the rectangle.
11. Type Open in the Push Button's Caption field.
12. Click the Actions icon on the left side of the Push Button Properties dialog.
13. Click the Insert Action button.
14. Locate and select the NeoDX category among the icons on the left side of the Action Selector.
15. After selecting the DirectX icon, select dxOpenFile from the right side of the screen. The following dialog box will appear:
16. In the Media Player ID field, enter the following if it's not already filled in:
This should be the same variable name you used for the dxCreate action in step 8. It's important that this variable be the same because we want to open this file into the same media player that will be created in the page enter action.
17. Click on the little yellow folder icon to the right of the Media File field and select a video file from your hard drive. (Any type of video that you can play with Windows Media Player should also work here.)
18. Your screen should now look like this:
19. Let's test the publication. Select Run or Run (From Start) from the Book menu.
20. Click the Open button to load the video file. Your screen should look something like this:
If you have VisualNEO for Windows's Debugging Info window open, you should see a list of variables similar to those below:
Notice that all of these variables are based on [Player1], the variable we supplied in the Media Player ID field for each of the NeoDX actions above. These variables are created automatically by NeoDX and contain current information about the status of the Media Player object. See the Understanding NeoDX Variables topic for more information on using these variables.
21. When you’re finished testing, click the publication window’s Close button or press the Esc key on your keyboard. We'll add play, pause and stop buttons to our media player next.
Adding Play, Stop and Pause buttons
The video looks good, but our media player is missing some critical components. Let's add some control buttons to make it work.
1. Create another Push Button just below the Open button.
2. Type Play in the Push Button's Caption field.
3. Click the Actions icon on the left side of the Push Button Properties dialog.
4. Click the Insert Action button.
5. Locate and select the NeoDX category among the icons on the left side of the Action Selector.
6. After selecting the DirectX icon, select dxPlay from the right side of the screen. The dxPlay Properties dialog box will appear.
7. In the Media Player ID field enter [Player1] just like we did earlier for the dxCreate and dxOpenFile actions.
8. Enter 1 in the Number of Times to Play Media field.
9. Click OK to assign the dxPlay action to the button, then click OK again to save the Push Button.
When you have finished, your screen should look like this:
11. Let's test the publication. Select Run or Run (From Start) from the Book menu.
12. Click the Open button to load the video file, then click the Play button.
13. When you’re finished testing, click the publication window’s Close button or press the Esc key on your keyboard.
Adding a Track Bar
Most professional media players include some type of slider or track bar to indicate the current playback position. We can do that too by linking a VisualNEO for Windows Track Bar object to our Media Player. Follow the steps below:
1. Create a Track Bar just below the large rectangle you created for the media player. (You can reduce the size of the rectangle if you need more room.) The Track Bar Properties dialog Box will appear.
2. Set the Track Bar's Appearance option to Horizontal.
3. In the Variable to Store Track Bar Value field, enter the following:
This variable is automatically created by NeoDX and will always contains the media player's current position. See the Understanding NeoDX Variables topic for more information on using media player variables.
4. Click the Actions icon on the left side of the Track Bar Properties dialog.
5. Because the [Player1.Position] variable is read-only, we need to use the dxSetPosition action to notify the media player whenever the Track Bar is adjusted manually. In the Track Bar's Value Changed action, type the following:
dxSetPosition "[Player1]" "[Player1.Position]" "Milliseconds"
6. Click OK to finish creating the Track Bar. Your screen should now look like this:
7. Next, place the mouse pointer over the Open button you created earlier and click the right mouse button. The Push Button Properties dialog box will appear.
8. Click the Actions icon on the left side of the Push Button Properties dialog.
9. You should see the dxOpenFile action that you entered earlier. Place the text cursor at the end of this command and press Enter to add a new line. Type the following on the new line:
TrackBarSetMax "TrackBar1" "[Player1.Length]"
Replace TrackBar1 above if the name of your Track Bar is different. NeoDX will automatically set the variable [Player1.Length] to the length (in milliseconds) of the file opened with dxOpenFile. Here we're simply assigning that number to the Track Bar's maximum value so that it matches the length of the video.
10. Select Run or Run (From Start) from the Book menu. Click the Open and Play buttons and the Track Bar should move from left to right as the video plays. You can also slide the Track Bar to manually set the video's current position.
Check out the sample publications in the "PlugIns\NeoDX\Sample Pubs" folder for additional DirectX examples.