I'm having two problems with switching bit rates in a dynamic stream.
On my player, I have two buttons, one for a low quality version and the other for a high quality version, which switch between the dynamic stream indexes 0 and 1 respectively.
Here is the function that controls the switch:
private function switchVideo(step:int):void
//step is either 1 or -1 depending on weather we're going up or down the bitrates
var newDynamicStreamIndex:int = _mediaPlayer.currentDynamicStreamIndex + step;
//perform a range check
if (newDynamicStreamIndex < 0 || newDynamicStreamIndex > _mediaPlayer.maxAllowedDynamicStreamIndex) return;
trace('attempting switch to:', newDynamicStreamIndex);
//make the switch
Here is the function that listens for the switch event
private function onDynamicStreamSwitchChange(e:DynamicStreamEvent):void
else trace('Switched to:', _mediaPlayer.currentDynamicStreamIndex);
Switching to the low version is fine, it all works, except it takes a long time to perform (around 15-20 seconds). I have a powerful quad core dedicated server runnimg my FMS, so I don't think computing power is the issue. I'm also on an 8mbps connection so agin, that is not the issue here.
My second issue is switching up. When I attempt this, I get the traced out 'attempting switch to: 1' message as expected, but the actual switch never occurs. I don't know if this is an issue with the FMS or the switchDynamicStreamIndex() function.
Incidentally, the autoSwitching does perform a switch up, but again the switch takes a long time to complete (around 30-40 seconds).
Any help with this issue would be greatly appreciated.
*** UPDATE ***
The manual switch does sometimes occur, but it takes a really long time!
The switching time depends on the client buffer state and the keyframe interval of the content. The switch is not complete until it is visible to the user, meaning the buffer has to play through. So if the client has buffered 15 seconds of content, it will take around 15 seconds to make the switch. This also depends on your FMS settings since keyframes can be generated on the fly.
This is easy to monitor if you turn on logging for the OSMF Flex project. You'll see something like this in your log:
Calling for switch to 4 at 1708 kbps
Switching to index 4 at 1708 kbps
Transition complete to index: 4 at 1708 kbps
The "NetStream.Play.Transition" means the server has acknowledged the request and has begun the switching process. The "NetStream.Play.TransitionComplete" is an in-stream event and this means the switch is visible to the user (the buffer has played thru and the new bitrate stream is now viewable). The time between the "Transition" and the "TransitionComplete" will be very close to the size of the current buffer. I don't belive we are logging the current buffer size right now, but you can easily do that in your player by getting to the netStream object via the LoadTrait (in sprint 10, sprint 9 will be the loadedContext). There is another thread here about getting to the netStream object if you want to try this yourself.
Hope that helps,