![]() |
![]() |
![]() |
SWFDEC Reference Manual | ![]() |
---|---|---|---|---|
enum SwfdecMouseCursor; SwfdecPlayer; void swfdec_init (void); SwfdecPlayer* swfdec_player_new (void); SwfdecPlayer* swfdec_player_new_from_file (const char *filename, GError **error); void swfdec_player_set_loader (SwfdecPlayer *player, SwfdecLoader *loader); gboolean swfdec_player_is_initialized (SwfdecPlayer *player); double swfdec_player_get_rate (SwfdecPlayer *player); void swfdec_player_get_image_size (SwfdecPlayer *player, int *width, int *height); void swfdec_player_iterate (SwfdecPlayer *player); void swfdec_player_render (SwfdecPlayer *player, cairo_t *cr, double x, double y, double width, double height); gboolean swfdec_player_handle_mouse (SwfdecPlayer *player, double x, double y, int button); guint swfdec_player_get_audio_samples (SwfdecPlayer *player); guint swfdec_player_get_audio_advance (SwfdecPlayer *player); void swfdec_player_set_audio_advance (SwfdecPlayer *player, guint samples); void swfdec_player_render_audio (SwfdecPlayer *player, gint16 *dest, guint start_offset, guint n_samples); SwfdecBuffer* swfdec_player_render_audio_to_buffer (SwfdecPlayer *player); const GList* swfdec_player_get_audio (SwfdecPlayer *player);
"initialized" gboolean : Read "latency" guint : Read / Write "mouse-visible" gboolean : Read
"audio-added" void user_function (SwfdecPlayer *player, SwfdecAudio *audio, gpointer user_data) : Run last "audio-removed" void user_function (SwfdecPlayer *player, SwfdecAudio *audio, gpointer user_data) : Run last "handle-mouse" gboolean user_function (SwfdecPlayer *player, gdouble x, gdouble y, gint button, gpointer user_data) : Run last "invalidate" void user_function (SwfdecPlayer *player, gdouble x, gdouble y, gdouble width, gdouble height, gpointer user_data) : Run last "iterate" void user_function (SwfdecPlayer *player, gpointer user_data) : Run last "launch" void user_function (SwfdecPlayer *player, gchar *url, gchar *target, gpointer user_data) : Run last "trace" void user_function (SwfdecPlayer *player, gchar *text, gpointer user_data) : Run last
A SwfdecPlayer is the main object used for playing back Flash files through Swfdec.
A player interacts with the outside world in a multitude of ways. The most important ones are described below.
Input is handled via the
SwfdecLoader class. A
SwfdecLoader is set on a new player using swfdec_player_set_loader()
.
When the loader has provided enough data, you can start playing the file.
This is done in steps by calling swfdec_player_iterate()
- preferrably as
often as swfdec_player_get_rate()
indicates. Or you can provide user input
to the player by calling for example swfdec_player_handle_mouse()
You can use swfdec_player_render()
to draw the current state of the player.
After that, connect to the SwfdecPlayer::invalidate signal to be notified of
changes.
Audio output is handled via the SwfdecAudio class. One SwfdecAudio object is created for every output using the SwfdecPlayer::audio-added signal.
typedef enum { SWFDEC_MOUSE_CURSOR_NORMAL, SWFDEC_MOUSE_CURSOR_NONE, SWFDEC_MOUSE_CURSOR_TEXT, SWFDEC_MOUSE_CURSOR_CLICK } SwfdecMouseCursor;
This enumeration describes the possible types for the SwfdecPlayer::mouse-cursor property.
typedef struct _SwfdecPlayer SwfdecPlayer;
This is the base object used for playing Flash files.
SwfdecPlayer* swfdec_player_new (void);
Creates a new player.
This function calls swfdec_init()
for you if it wasn't called before.
Returns : | The new player |
SwfdecPlayer* swfdec_player_new_from_file (const char *filename, GError **error);
Tries to create a player to play back the given file. If the file does not
exist or another error occurs, NULL is returned.
This function calls swfdec_init()
for you if it wasn't called before.
filename : |
name of the file to play |
error : |
return location for error or NULL |
Returns : | a new player or NULL on error. |
void swfdec_player_set_loader (SwfdecPlayer *player, SwfdecLoader *loader);
Sets the loader for the main data. This function only works if no loader has
been set on player
yet.
swfdec_player_set_loader()
and
not use conveniencse functions such as swfdec_player_new_from_file()
.
player : |
a SwfdecPlayer |
loader : |
the loader to use for this player. Takes ownership of the given loader. |
gboolean swfdec_player_is_initialized (SwfdecPlayer *player);
Determines if the player
is initalized yet. An initialized player is able
to provide basic values like width, height or rate. A player may not be
initialized if the loader it was started with does not reference a Flash
resources or it did not provide enough data yet. If a player is initialized,
it will never be uninitialized again.
player : |
a SwfdecPlayer |
Returns : | TRUE if the basic values are known. |
double swfdec_player_get_rate (SwfdecPlayer *player);
Queries the framerate of this movie. This number specifies the number of frames that are supposed to pass per second. It is a multiple of 1/256.
player : |
a SwfdecPlayer |
Returns : | The framerate of this movie or 0 if it isn't known yet. |
void swfdec_player_get_image_size (SwfdecPlayer *player, int *width, int *height);
If the size of the movie is already known, fills in width
and height
with
the size. Otherwise width
and height
are set to 0.
player : |
a SwfdecPlayer |
width : |
integer to store the width in or NULL |
height : |
integer to store the height in or NULL |
void swfdec_player_iterate (SwfdecPlayer *player);
Advances player to the next frame. You should make sure to call this function
as often per second as swfdec_player_get_rate()
indicates.
player : |
the SwfdecPlayer to iterate |
void swfdec_player_render (SwfdecPlayer *player, cairo_t *cr, double x, double y, double width, double height);
Renders the given area of the current frame to cr
.
player : |
a SwfdecPlayer |
cr : |
cairo_t to render to |
x : |
x coordinate of top left position to render |
y : |
y coordinate of top left position to render |
width : |
width of area to render or 0 for full width |
height : |
height of area to render or 0 for full height |
gboolean swfdec_player_handle_mouse (SwfdecPlayer *player, double x, double y, int button);
Updates the current mouse status. If the mouse has left the area of player
,
you should pass values outside the movie size for x
and y
.
player : |
a SwfdecPlayer |
x : |
x coordinate of mouse |
y : |
y coordinate of mouse |
button : |
1 for pressed, 0 for not pressed |
Returns : | TRUE if the mouse event was handled. A mouse event may not be handled if the user clicked on a translucent area for example. |
guint swfdec_player_get_audio_samples (SwfdecPlayer *player);
Gets the amount of audio samples to be played back in the current frame. The amount of samples may differ by one between frames to work around rounding issues.
player : |
a SwfdecPlayer |
Returns : | amount of samples in the current frame. |
guint swfdec_player_get_audio_advance (SwfdecPlayer *player);
Queries the current latency of the audio stream. See swfdec_decoder_set_audio_advance()
for details.
player : |
a SwfdecPlayer |
Returns : | the current latency in samples |
void swfdec_player_set_audio_advance (SwfdecPlayer *player, guint samples);
Sets the current latency in player
to samples
. The latency determines how soon
sound events start playing. This function is intended to be set when iterating
too late or when handling mouse events so that audio based on those events
are started at the right point.
You can think of audio and video as two timelines that normally advance at the same
speed. Since audio has a much higher granularity (44100th of a second vs 256th of a
second) and an iteration advances the video one time, this function is provided to
advance the audio seperately.
Note that when iterating the video "catches up" to the audio as the audio advance is
reduced by the amount of samples in the current frame. So if you want to use a
constant advance, you'll have to call this function before every iteration with an
updated value.
player : |
a SwfdecPlayer |
samples : |
how many frames the audio is advanced since the last iteration in frames. |
void swfdec_player_render_audio (SwfdecPlayer *player, gint16 *dest, guint start_offset, guint n_samples);
Renders the data for this frame into the given location. The data is added to dest
,
so you probably want to initialize dest
to silence before calling this function.
player : |
a SwfdecPlayer |
dest : |
location to add audio signal to. The audio signal will be in 44100kHz signed 16bit stereo. |
start_offset : |
offset in samples at which to start rendering. The offset is
calculated relative to the last iteration, so the value set
by swfdec_player_set_audio_advance() is ignored.
|
n_samples : |
amount of samples to render. |
SwfdecBuffer* swfdec_player_render_audio_to_buffer (SwfdecPlayer *player);
Renders the audio for this frame into a new buffer. This is a simplification
for swfdec_player_render_audio()
.
player : |
a SwfdecPlayer |
Returns : | a new SwfdecBuffer fille with the audio for this frame. |
const GList* swfdec_player_get_audio (SwfdecPlayer *player);
Returns a list of all currently active audio streams in player
.
player : |
a SwfdecPlayer |
Returns : | A GList of SwfdecAudio. You must not modify or free this list. |
initialized
" property"initialized" gboolean : Read
TRUE when the player has initialized its basic values.
Default value: FALSE
latency
" property"latency" guint : Read / Write
audio latency in samples.
Allowed values: <= 441000
Default value: 0
void user_function (SwfdecPlayer *player, SwfdecAudio *audio, gpointer user_data) : Run last
Emitted whenever a new audio stream was added to player
.
player : |
the SwfdecPlayer affected |
audio : |
the audio stream that was added |
user_data : |
user data set when the signal handler was connected. |
void user_function (SwfdecPlayer *player, SwfdecAudio *audio, gpointer user_data) : Run last
Emitted whenever an audio stream was removed from player
. The stream will
have been added with the SwfdecPlayer::audio-added signal previously.
player : |
the SwfdecPlayer affected |
audio : |
the audio stream that was removed |
user_data : |
user data set when the signal handler was connected. |
gboolean user_function (SwfdecPlayer *player, gdouble x, gdouble y, gint button, gpointer user_data) : Run last
this signal is emitted whenever player
should respond to a mouse event. If
any of the handlers returns TRUE, swfdec_player_handle_mouse()
will return
TRUE. Note that unlike many event handlers in gtk, returning TRUE will not
stop further event handlers from being invoked. Use g_signal_stop_emission()
in that case.
player : |
the SwfdecPlayer affected |
x : |
new x coordinate of the mouse |
y : |
new y coordinate of the mouse |
button : |
1 if the button is pressed, 0 if not |
user_data : |
user data set when the signal handler was connected. |
Returns : | TRUE if this handler handles the event. |
void user_function (SwfdecPlayer *player, gdouble x, gdouble y, gdouble width, gdouble height, gpointer user_data) : Run last
This signal is emitted whenever graphical elements inside the player have changed. The coordinates describe the smallest rectangle that includes all changes.
player : |
the SwfdecPlayer affected |
x : |
x coordinate of invalid region |
y : |
y coordinate of invalid region |
width : |
width of invalid region |
height : |
height of invalid region |
user_data : |
user data set when the signal handler was connected. |
void user_function (SwfdecPlayer *player, gpointer user_data) : Run last
Emitted whenever the player iterates.
player : |
the SwfdecPlayer affected |
user_data : |
user data set when the signal handler was connected. |
void user_function (SwfdecPlayer *player, gchar *url, gchar *target, gpointer user_data) : Run last
Emitted whenever the player
encounters an URL that should be loaded into
a target the Flash player does not recognize. In most cases this happens
when the user clicks a link in an embedded Flash movie that should open a
new web page.
The effect of calling any swfdec functions on the emitting player
is undefined.
player : |
the SwfdecPlayer affected |
url : |
URL to open |
target : |
target to load the URL into |
user_data : |
user data set when the signal handler was connected. |
void user_function (SwfdecPlayer *player, gchar *text, gpointer user_data) : Run last
Emits a debugging string while running. The effect of calling any swfdec
functions on the emitting player
is undefined.
player : |
the SwfdecPlayer affected |
text : |
the debugging string |
user_data : |
user data set when the signal handler was connected. |