Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLVPlayback/VideoPlayer: How to access VideoPlayer.load() method that accepts 5 parameters?

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.

like image 494
anon Avatar asked Oct 22 '22 04:10

anon


1 Answers

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
    • Or FLVPlayback_116_air.swc if you're targeting Adobe AIR, not Flash Player / web
  • 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!

like image 198
Jeff Ward Avatar answered Oct 27 '22 10:10

Jeff Ward