Chapter 12: Creating Custom Media Content continued
Figure 12.1 shows the Advanced Script Indexer displaying three markers in a file named jeanne.wma. This file is included with the Windows Media Player SDK.
Figure 12.1 Advanced Script Indexer displaying a file with three markers.
The three markers in jeanne.wma are named marker1, marker2, and marker3. They could have any names as long as each name is different. An application can listen for a marker name and respond when the marker is encountered in the specified file.
The file jeanne.wma has a duration of 56.1 seconds. Markers are placed at the following points in the file:
In this file, the markers are used to mark the opening, middle, and closing thematic portions of the music. But markers could be used for many different reasons. For example, you might want to divide a movie into scenes and allow users to switch to any scene they want at any time. Many DVD players allow this, making it possible for users to go back to named scenes. Moving to a specific position in a file is called seeking.
Using Markers with the Player
Windows Media Player can work with files that have markers embedded in them. When you choose File Markers from the View menu, you are presented with a list of the named markers in the currently playing file.
Figure 12.2 shows the Player when it is ready for you to select a position in the file by choosing a marker. The thumb of the seek bar is on the left side, indicating that the song has just started.
Figure 12.2 Getting ready to seek to a new position with a marker.
When the third marker, marker3, is chosen, the Player moves the file position to 43 seconds into the song. Figure 12.3 shows the Player after the position has moved to the third marker.
Figure 12.3 Position of the third marker in the file.
You can use this property of the Media object to determine the number of markers in a file.
This method of the Media object will give you the name of an indexed marker. For example, you could get the name of the third marker with getMarkerName(3).
This method of the Media object gives the time of an indexed marker in seconds. For example, you can get the time of the second marker with getMarkerTime(2).
You can use this method of the Controls object to seek to the position of the indexed marker. For example, to seek to the position of the first marker in a file, you would write to currentMarker(1). You can also use currentMarker to read the position of the current marker. The current marker duration extends from the position of the last marker encountered to just before the next marker.
The following JScript code shows how to use markers in script. The name of the Player object is Player1 and the function GoMarker is called with the parameter of mymark, which is the marker number you want to seek to. This script is for use in a Web page. If you were using the script in a skin, the object name would be player.
function GoMarker (mymark)
The function reads a marker number and uses it to seek to the position of the numbered marker in a file. Then the marker name, marker time, and total number of markers in the file are copied and displayed in individual text boxes.
For more information about markers, see the Windows Media Player SDK.