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 :)