Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6046997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:18:11+00:00 2026-05-23T07:18:11+00:00

I’ve written a little OSMF player that streams via RTMP from Amazon Cloudfront. There’s

  • 0

I’ve written a little OSMF player that streams via RTMP from Amazon Cloudfront. There’s a known issue, the mp3 duration is not correctly readed from metadata and thus the seek function is not working.
I know there’s a workaround implying the use of getStreamLength function of NetConnection, which I successfully implemented in a previous non-OSMF player, but now I don’t know how and when to call it, in terms of OSMF Events and Traits.
This code is not working:

  protected function initApp():void
  {
    //the pointer to the media
    var resource:URLResource = new URLResource( STREAMING_PATH );

    // Create a mediafactory instance
    mediaFactory = new DefaultMediaFactory();

    //creates and sets the MediaElement (generic) with a resource and path
    element = mediaFactory.createMediaElement( resource );

    var loadTrait:NetStreamLoadTrait = element.getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;
    loadTrait.addEventListener(LoaderEvent.LOAD_STATE_CHANGE, _onLoaded);
    player = new MediaPlayer( element );

    //Marker 5: Add MediaPlayer listeners for media size and current time change
    player.addEventListener( DisplayObjectEvent.MEDIA_SIZE_CHANGE, _onSizeChange );
    player.addEventListener( TimeEvent.CURRENT_TIME_CHANGE, _onProgress );

    initControlBar();
  }
  private function onGetStreamLength(result:Object):void {
    Alert.show("The stream length is " + result + " seconds"); 
    duration = Number(result);
  }

  private function _onLoaded(e:LoaderEvent):void
  {
    if (e.newState == LoadState.READY)
    {
      var loadTrait:NetStreamLoadTrait = player.media.getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;

      if (loadTrait && loadTrait.netStream)

      {
      var responder:Responder = new Responder(onGetStreamLength);
      loadTrait.connection.call("getStreamLength", responder, STREAMING_PATH);
      }
    }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:18:12+00:00Added an answer on May 23, 2026 at 7:18 am

    The simple answer

    You cannot pass the full stream url STREAMING_PATH to this method:
    loadTrait.connection.call(“getStreamLength”, responder, STREAMING_PATH);

    You need to use just the stream name, which the path to the right of the FMS instance

    So if the url (or connection.uri) is:
    rtmp://example.com:80/_myfms/mp3:the/stream/name/foo

    You only want to pass the stream name, not the server instance:
    ‘mp3:the/stream/name/foo’

    The complex answer (Extend NetLoader class):

    package{
    // You can extend the NetLoader class to have it automatically ask for duration 
    // and dispatch an event when it is received. 
    
    // This is a super simple, partial example, but the stub should get you going
    
    // TODO: define imports here (omitted for example's sake)
    
    class MyNetLoader extends NetLoader
    {
      // useful for adding an event listener outside
      public static const GOT_STREAM_DURATION:String = "gotStreamDuration";
    
      // constructor
      public function MyNetLoader(factory:NetConnectionFactoryBase = null)
      {
         super( factory );
      }
    
      // override the parent method that creates the actual NetStream 
      override protected function createNetStream( connection:NetConnection, resource:URLResource) : NetStream
      {
         // usually you pass just the stream name, not the full uri 
         // there is likely a cleaner way to extract the stream name...
         var streamName:String = resource.url.replace('rtmp://example.com:80/_myfms/', '');
    
         // request duration from FMS
         connection.call('getStreamLength', new Responder( this.onResult ), streamName);
    
         return super.createNetStream(connection, resource);
       }
    
       // receives the getStreamLength callback from FMS
       protected function onResult( info:Object ):void
       {
         _duration = Number(info) * 1000; // duration, in ms
    
         dispatchEvent( new Event(GOT_STREAM_DURATION) );
    
         trace('Duration is: ' + _duration);
       }
       // read-only getter for duration
       public function get duration():uint
       {
         return _duration as uint;
       }
     }
    }
    

    Then, in your other code:

    ...
        // create the resource
        var resource:URLResource = new URLResource('rtmp://example.com:80/_something/the/stream/name/foo');
    
        // create your custom loader, adding a listener for the duration callback
        var loader:MyNetLoader = new MyNetLoader();
    
        // listen for the duration event
        loader.addEventListner(MyNetLoader.GOT_STREAM_DURATION, function(event:Event):void{
                trace('Got the duration outside: ' + (event.target as MyNetLoader).duration);
        });
    
        // I use an AudioElement here, but it could be any of the typed or generic elements
        // as long as the constructor accepts (resource, loader)
        // You dont want to use the factory to create the element, because (to my knowledge)
        // you cant pass a custom loader to the factory (unless you extended it)
        var myElement:AudioElement = new AudioElement( resource, loader );
    
        // pass the element to the player. I dont pass to the constructor in this example because
        // in most real-world cases, you would already have an instance of MediaPlayer
        player = new MediaPlayer();
        player.media = myElement;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I am doing a simple coin flipping experiment for class that involves flipping a
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.