AS3, NetConnection / NetStream: is there any reasonable way to split the source URL?

Problem

I need to replace the mx: VideoDisplay component in an existing Flex project using a specially created component.

To achieve this, I have to match its current interface, so my component receives videos (through the original parameter) in the form:

  • /data/myflvfile.flv (if the file is played locally)
  • rtmp: //streamcloud.myserver.com/cfx/st/somedirectory/myflvfile.flv (if the file was transferred from Cloudfront)

My new component is based on NetConnection and NetStream. For any of the above entries, I have to split the input into two lines: one for the NetConnection.connect (NetConnectionStr) method, and the other for the NetStream.play (NetStreamStr) method. For example:

  • Given /data/myflvfile.flv then:
    • NetConnectionStr = null
    • NetStreamStr = "/ data / myflvfile"
  • Given rtmp: //streamcloud.myserver.com/cfx/st/somedirectory/myflvfile.flv , then:
    • NetConnectionStr = "rtmp: //streamcloud.myserver.com/cfx/st"
    • NetStreamStr = "somedirectory / myflvfile"
  • If rtmp: //streamcloud.myserver.com/cfx/st/somedirectory/subdirectory/myflvfile.flv is specified , then:
    • NetConnectionStr = "rtmp: //streamcloud.myserver.com/cfx/st"
    • NetStreamStr = "somedirectory / subdirectory / myflvfile"

The construction of two lines is very obvious for the case of "local files", but in others it is difficult. The problem is that I have no reasonable way to guess which part of the input is the server URL and which part is the stream name + directory structure.

In some examples found on the Internet, people just guess that the last part of the source (that’s after the last found //) is the name NetStream. In my case, this is not always the case, because streams can be in subdirectories on the server. This is even worse because server names may contain "/" characters!

Problem Solving Strategies

Connect to the server, get its real URL, search for the stream name

Because NetConnection seems smart, my first attempt was to call the connect method with the full source url. For example, this RTMP: //streamcloud.myserver.com/cfx/st/somedirectory/subdirectory/myflvfile.flv

NetConnection is a success:

  • connection.connect ( RTMP: //streamcloud.myserver.com/cfx/st/ )
  • connection.connect ( RTMP: //streamcloud.myserver.com/cfx/st/somedirectory/ )
  • ...
  • connection.connect ( RTMP: //streamcloud.myserver.com/cfx/st/somedirectory/subdirectory/myflvfile.flv )

Then I hoped somehow to restore the "real" server URL ( rtmp: //streamcloud.myserver.com/cfx/st ), so I could guess part of the stream ( somedirectory // myflvfile subdirectory ).

Unfortunately, I did not find a way to get the real server address from the NetConnection object (connection.uri returns the exact input back). So this seems like a dead end.

Connect to server, iteratively retrieve streams

Another strategy could be connecting to the server, and then trying to iteratively (from the very end) play streams until it works:

Given rtmp: //streamcloud.myserver.com/cfx/st/somedirectory/subdirectory/myflvfile.flv :

  • Try 1: stream.play ( myflvfile ) FAIL
  • Try 2: stream.play ( subdirectory / myflvfile ) FAIL
  • Try 3: stream.play ( somedirectory / subdirectory / myflvfile ) SUCCESS

But this is a very ugly way, and I'm looking for the best solution.

The best solution?

Is there a good way to solve this problem? Does anyone know how they do this in the original VideoDisplay component (if it is based on NetConnection / NetStream objects?)?

Thanks in advance for any help and / or comments on this issue :)

+7
source share
3 answers
var match:Array = path.match('rtmp://(.*/.*/.*/)'); var server:String = match[0]; var file:String = removeExtension(path.replace(match[1], '')); var channel:String = removeExtension(path.replace(match[2], '')); 

ref: http://onyx-vj.googlecode.com/svn/trunk/Onyx-VJ%203.0.0/OnyxCore/onyx/core/ProtocolRTMP.as

0
source

Without testing the solution against a running rtmp service, it's hard for you to verify this, but consider the following refinement to your second, less desirable strategy:

  • create netconnection as usual

  • the first time connect () is successful, iterating through possible combinations of service and asset ("rtmp: //streamcloud.myserver.com/cfx/" and "/st/somedirectory/subdirectory/myflvfile.flv, etc.) and create parallel NetStream for each of them - so you do not need to wait for sequential detection

  • if one of NetStreams sends a success event, attaches it to the display and discards all the others on the floor (they may still fail)

  • maybe you could save a successful service / asset pair that worked to speed things up if the connection needs to be reused

Sounds like an unpleasant problem!

0
source

I am confused by your question. Is there any part of your rtmp connection that is serial? Do you regularly change streaming providers? If it is consistent, then at least half of the battle will win. How can I connect to rtmp, what happens in the connection is always the same. The last part is more dynamic, which is transmitted in the same way; [folder] / [video name]. I will do all my parsing only on what is passed, but then I have one rtmp provider.

0
source

All Articles