Working with Digital Media in PDF Documents
Media Players: Control, Settings, Renditions, and Events
8
Media Players Topics
Accessing a List of Active Players
Specifying Playback Settings
Accessing a List of Active Players
To obtain a list of available players, call the
app.media
object’s
getPlayers
method,
which accepts an optional parameter specifying the MIME type and returns a
PlayerInfoList
object. The
PlayerInfoList
object is an array of
PlayerInfo
objects that can be filtered using its
select
method.
The following code sample shows how to obtain a list of all available players:
var mp = app.media.getPlayers();
The following code sample shows how to obtain a list of all available MP3 players and prints
them out to the console:
var mp = app.media.getPlayers("audio/MP3");
for (var i = 0; i < mp.length; i++) {
console.println("\nmp[" + i + "] Properties");
for (var p in mp[i])
console.println(p + ": " + mp[i][p]);
}
To filter the list of players using the
PlayerInfoList
object’s
select
method, you may
supply an optional
object
parameter which may contain any combination of
id
,
name
,
and
version
properties, each of which may be either a string or a regular expression. For
example, the following code obtains the QuickTime media player:
var mp = app.media.getPlayers().select({id: /quicktime/i});
In addition, the
doc.media
object’s
getOpenPlayers
method returns an array of all
currently open
MediaPlayer
objects. With this array, you can stop or close all players,
and manipulate any subset of the open players. The following example stops all running
players in the document:
var players = doc.media.getOpenPlayers(oDoc);
for (var i in players)
players[i].stop();
Acrobat JavaScript Scripting Guide
145