2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
24 #include "swfdec_movie_clip_loader.h"
25 #include "swfdec_as_array.h"
26 #include "swfdec_as_internal.h"
27 #include "swfdec_as_strings.h"
28 #include "swfdec_debug.h"
29 #include "swfdec_decoder.h"
30 #include "swfdec_player_internal.h"
31 #include "swfdec_resource.h"
34 G_DEFINE_TYPE (SwfdecMovieClipLoader
, swfdec_movie_clip_loader
, SWFDEC_TYPE_AS_RELAY
)
37 swfdec_movie_clip_loader_class_init (SwfdecMovieClipLoaderClass
*klass
)
42 swfdec_movie_clip_loader_init (SwfdecMovieClipLoader
*movie_clip_loader
)
46 SWFDEC_AS_NATIVE (112, 0, swfdec_movie_clip_loader_construct
)
48 swfdec_movie_clip_loader_construct (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
49 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
52 SwfdecAsObject
*array
;
53 SwfdecMovieClipLoader
*loader
;
55 if (!swfdec_as_context_is_constructing (cx
))
58 loader
= g_object_new (SWFDEC_TYPE_MOVIE_CLIP_LOADER
, "context", cx
, NULL
);
59 swfdec_as_object_set_relay (object
, SWFDEC_AS_RELAY (loader
));
61 array
= swfdec_as_array_new (cx
);
62 SWFDEC_AS_VALUE_SET_OBJECT (&val
, object
);
63 swfdec_as_array_push (array
, &val
);
64 SWFDEC_AS_VALUE_SET_OBJECT (&val
, array
);
65 swfdec_as_object_set_variable_and_flags (object
, SWFDEC_AS_STR__listeners
,
66 &val
, SWFDEC_AS_VARIABLE_HIDDEN
| SWFDEC_AS_VARIABLE_PERMANENT
);
68 SWFDEC_AS_VALUE_SET_OBJECT (ret
, object
);
71 SWFDEC_AS_NATIVE (112, 100, swfdec_movie_clip_loader_loadClip
)
73 swfdec_movie_clip_loader_loadClip (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
74 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
76 SwfdecMovieClipLoader
*loader
;
81 SWFDEC_AS_CHECK (SWFDEC_TYPE_MOVIE_CLIP_LOADER
, &loader
, "sv", &url
, &target
);
83 result
= swfdec_resource_load_movie (SWFDEC_PLAYER (cx
), &target
, url
,
85 SWFDEC_AS_VALUE_SET_BOOLEAN (rval
, result
);
88 SWFDEC_AS_NATIVE (112, 102, swfdec_movie_clip_loader_unloadClip
)
90 swfdec_movie_clip_loader_unloadClip (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
91 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
93 SwfdecMovieClipLoader
*loader
;
96 SWFDEC_AS_CHECK (SWFDEC_TYPE_MOVIE_CLIP_LOADER
, &loader
, "v", &target
);
98 swfdec_resource_load_movie (SWFDEC_PLAYER (cx
), &target
, "", NULL
, loader
);
101 SWFDEC_AS_NATIVE (112, 101, swfdec_movie_clip_loader_getProgress
)
103 swfdec_movie_clip_loader_getProgress (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
104 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
106 SwfdecMovieClipLoader
*loader
;
110 SwfdecResource
*resource
;
111 SwfdecAsValue loaded
, total
;
113 SWFDEC_AS_CHECK (SWFDEC_TYPE_MOVIE_CLIP_LOADER
, &loader
, "s", &target
);
115 movie
= swfdec_player_get_movie_from_string (SWFDEC_PLAYER (cx
), target
);
118 ret
= swfdec_as_object_new_empty (cx
);
119 SWFDEC_AS_VALUE_SET_OBJECT (rval
, ret
);
120 resource
= swfdec_movie_get_own_resource (movie
);
121 if (resource
== NULL
|| resource
->decoder
== NULL
) {
122 loaded
= swfdec_as_value_from_integer (cx
, 0);
123 total
= swfdec_as_value_from_integer (cx
, 0);
125 loaded
= swfdec_as_value_from_integer (cx
, resource
->decoder
->bytes_loaded
);
126 total
= swfdec_as_value_from_integer (cx
, resource
->decoder
->bytes_total
);
128 swfdec_as_object_set_variable (ret
, SWFDEC_AS_STR_bytesLoaded
, &loaded
);
129 swfdec_as_object_set_variable (ret
, SWFDEC_AS_STR_bytesTotal
, &total
);