5
votes

I want to use the following load() method that accepts five parameters so that I can load a small "excerpt" from a larger video:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/video/VideoPlayer.html#load()

In particular, the startTime and duration parameters seem to be what I need, but I am getting errors that seem to indicate that I don't have the right object/version of something, even though the Adobe docs say that it should work. Here are my steps:

  • Start a new, blank FLA document (AS3).
  • Drag an FLVPlayback component to the stage and name it vPlayer.
  • Create a new layer and add Actionscript in frame 1:

    import fl.video.*;
    
    var innerPlayer = vPlayer.getVideoPlayer(vPlayer.activeVideoPlayerIndex);
    trace(innerPlayer); // "[object VideoPlayer]" appears in Output window
    
    innerPlayer.load(
          "RTMP://..."
        , 0 // totalTime
        , false // isLive
        , 60 // startTime
        , 10 // duration
    );
    

This should give me a ten-second clip starting from the one-minute mark, but I keep getting errors like ArgumentError: Error #1063: Argument count mismatch on fl.video::VideoPlayer/load(). Expected 1, got 5.

I've also tried casting innerPlayer to fl.video.VideoPlayer, but that doesn't work.

What am I doing wrong?


EDITS: Even though I'm on CS4/AS3 and the documentation claims to apply to CS4/AS3, the class files in my "Component Source" folder don't seem to match the documentation. I also tried this in CS6, and I got "1137: Incorrect number of arguments. Expected no more than 3."

@SunilD. - For CS4: FLVPlayback.VERSION=2.1.0.19, and I am targeting Flash Player 10 (the most recent available)+AS3. For CS6, FLVPlayback.VERSION=2.5.0.26, and I am targeting Flash Player 11.4.

In CS4 and CS6, the errors say that VideoPlayer load() only requires one argument (with two optional), and play() has three optional arguments. The output of describeType(innerPlayer) confirms:

<type name="fl.video::VideoPlayer" base="flash.media::Video" isDynamic="false" isFinal="false" isStatic="false">
    ...
  <method name="play" declaredBy="fl.video::VideoPlayer" returnType="void">
    <parameter index="1" type="String" optional="true"/>
    <parameter index="2" type="Number" optional="true"/>
    <parameter index="3" type="Boolean" optional="true"/>
  </method>
    ...
  <method name="load" declaredBy="fl.video::VideoPlayer" returnType="void">
    <parameter index="1" type="String" optional="false"/>
    <parameter index="2" type="Number" optional="true"/>
    <parameter index="3" type="Boolean" optional="true"/>
  </method>
    ...
</type>

Other notes: Flash CS6 is up to date. Manually installing the FLVPlayback 2.5 component didn't work.

1
well, it seems clear that vPlayer.getVideoPlayer() is not returning an instance of a VideoPlayer. You can trying casting innerPlayer as such, but that won't work unless vPlayer.getVideoPlayer() actually returns one. Without seeing more code - it's impossible to comment further.hunter
@hunter - I added a trace() statement that seems to indicate that it is an instance of VideoPlayer, and when I force a cast, it does not return null. The code I posted was pretty much everything! I added an import statement at the top.anon
Yikes - what a pain in the a$$. To be honest, I always work with 100% AS3 (no components), so maybe I'm not the best person to answer. However, I fired up Flash CS6, and tried your code, and got the same error(s). I tried to declare and instantiate a VideoPlayer object directly, and the load() function requested 3 params. Obtaining a VideoPlayer object through FLVPlayback.getVideoPlayer() resulted in load() accepting only 1 param. I know this doesn't help you much, but at least you know it's not some glitch with your component files.hunter
I would debug this by taking more steps to figure out exactly what object you're working with. Since the trace() output seems to indicate you have a VideoPlayer object, maybe it's some earlier version of the VideoPlayer API. You might try inspecting the output of describeType(innerPlayer) ... (You can see what parameters that load() method actually has, or find other clues to confirm what this object actually is). You might also double check your publish settings and, make sure you're publishing a SWF that is targeting as recent a version of Flash Player as possible.Sunil D.
Not sure how helpful this is, but the FLVPLayback component has a VERSION constant. The version # in the docs is 2.1.023. What does trace(FLVPlayback.VERSION) output in your environment? How many arguments does your VideoPlayer.play() method accept? That should have the same args as the load() method... Finally, does it make any difference if you get the player with the visibleVideoPlayerIndex instead of activeVideoPlayerIndex? Or how about if you set activePlayerIndex=1 (default is 0) and try to use that?Sunil D.

1 Answers

3
votes

Anon, I think this is an issue of poor documentation / too many different products (Flash, Flex, player, flvplayback component) with different versions.

I was able to get the .load() call to work with all 5 arguments (and verified that it did start playing at the specified start time), but only by compiling a new FLVPlayback_116.swc from the latest Flex SDK source code (Flex 4.6 with playerglobal.swc version 11.6).

See my screenshot.

Might as well see if it works for you. Here's what you'll need to do:

  • Remove the FLVPlayback component from your library - this defines conflicting classes with the updated version.
  • Download my FLVPlayback_116.swc library
  • In Flash, open the File -> ActionScript Settings dialog, under the library path tab, click 'Browse to SWC file' and locate the FLVPlayback_116.swc file you just downloaded. My screenshot above shows this dialog and how the FLVPlayback_116.swc file is listed after being added.
  • In the code (see below):
    • You need to set: fl.video.VideoPlayer.iNCManagerClass = fl.video.NCManager;
    • Rather than using innerPlayer = vPlayer.getVideoPlayer you'll need to use innerPlayer = new VideoPlayer(width,height) and then addChild(innerPlayer) and innerPlayer.play()
    • I had to add the innerVideo.play() call to start the video playing (which I assume the GUI would handle)

Here's my code (also visible in the screenshot):

import fl.video.*;

fl.video.VideoPlayer.iNCManagerClass = fl.video.NCManager;
var innerPlayer = new VideoPlayer(640,480);
addChild(innerPlayer);

innerPlayer.load(
      "http://10.0.1.3/test.flv"
    , 0 // totalTime
    , false // isLive
    , 5 // startTime
    , 5 // duration
);
innerPlayer.play();

Also, you can see that my describeType of VideoPlayer shows the proper number of arguments:

<method name="load" declaredBy="fl.video::VideoPlayer" returnType="void">
  <parameter index="1" type="String" optional="false"/>
  <parameter index="2" type="Number" optional="true"/>
  <parameter index="3" type="Boolean" optional="true"/>
  <parameter index="4" type="Number" optional="true"/>
  <parameter index="5" type="Number" optional="true"/>
  <metadata name="__go_to_definition_help">
    <arg key="pos" value="41308"/>
  </metadata>
</method>

<method name="play" declaredBy="fl.video::VideoPlayer" returnType="void">
  <parameter index="1" type="String" optional="true"/>
  <parameter index="2" type="Number" optional="true"/>
  <parameter index="3" type="Boolean" optional="true"/>
  <parameter index="4" type="Number" optional="true"/>
  <parameter index="5" type="Number" optional="true"/>
  <metadata name="__go_to_definition_help">
    <arg key="pos" value="34410"/>
  </metadata>
</method>

UPDATE: I've updated the library so that you can instantiate an FLVPlayback(w,h) and hence apply skins or whatnot -- treat it just like you would the vPlayer in your code above (except I added the width/height constructor args, since the size used to come from the component on-stage). Instantiate it like so:

  var vPlayer:FLVPlayback = new FLVPlayback(640,480);
  vPlayer.skin = "http://10.0.1.3/skin.swf"; // optional skin
  addChild(vPlayer);
  var innerPlayer = vPlayer.getVideoPlayer(vPlayer.activeVideoPlayerIndex);
  innerPlayer.load(
                   "http://10.0.1.3/test.flv"
                   , 0 // totalTime
                   , false // isLive
                   , 5 // startTime
                   , 5 // duration
                   );

Note - to use a skin, I compiled one of the FLA examples from Flash CS6... I tried using a skin I found on the Internet and it didn't work - it was likely compiled for an older version. See this skinned screenshot and download my skin.swf.

Good luck, and let me know if you need further info!