I know the post is a bit old, but I also want some advice on how is the best way to do it.
There are two possible technical approaches to this:
1. Create a ProxyElement which would switch from the ad and the main video content and where you can control the pre-buffering behavior. The closest sample for this is OSMF\1.5gm\apps\samples\framework\ExamplePlayer\org\osmf\examples\switchingproxy\Switchin gProxyElement.as.
You'll need to use the Traits API and If you are working on a plugin, this is the only option you have.
2. If you are working on custom video player, the following approach might be somewhat simpler.
2.1 Create a custom MediaPlayer (MyMediaPlayer extends MediaPlayer)
2.2 Add a prebuffer method (and implement it ~= mute, play, pause, seek(0), unmute)
2.3 Use this class for controlling the playback and the prebuffering for both your main video and the ads
Let us know which approach you choose to implement. I'd really like to get your feedback on this.
Thanks for your reply and suggestions.
I was creating each element as soon the player need them to be played, but to do a pre-buffer/load I will need to create all the elements at the same time.
I was trying to discover how I could start to load an element without having to pass it to the mediaPlayer, the SwitchingProxyElement give me the hint on how to do it.
As my player should be flexible (should be able to have or not a pre-roll and/or post-roll) and I have some custom view for each state (initial thumb, pre-roll, video content, post-roll, related list), I think I'll have to mix a little the 2 approaches you suggested, managing the load of my elements individually in my MainPlayer class but not as a ProxyElement or extending the MediaPlayer.
As I have some view states, I will need to keep track and control of each element to know how to manage my views and to be able to replay each of them separately after they are all played. So I dont think using a SerialElement or any extension of that will help in an easy way, I would need to pass a lot of references to be able to manage my player in a custom class.
Neither extending MediaPlayer, I would need to hack it to handle 2 media elements, because when the mediaPlayer.media is changed it automatically unload the current media element, so dont think its not a good idea. As I'm already using composition, I think it will be easier to manage each element by itself and control what and when to pass do mediaPlayer instance. I'll try fist using the LoadTrait, if I dont have success will try using the AudioTrait and PlayTrait as you also suggested.
Do you have any other suggestion with this scenario?
So I choose the 2nd approach, I know that doing a refactoring it could be done using proxy elements and letting my custom media player to manage them. But its working for now.
Thanks for the suggestios Andrian.