Reply
Brightcove Team
BC-ChrisD
Posts: 121
Registered: ‎12-07-2008
0 Kudos

Controlling Player Volume with the Player APIs

[ Edited ]
This comes up from time to time so I thought it was worth making an example. Sometimes folks want to have their Brightcove 3 players load with the volume set to something less the 100%. This is very easy to accomplish by using the setVolume() method of the VideoPlayer module.

http://help.brightcove.com/developer/docs/playerapi/player-API.cfm#VideoPlayer%20Module

setVolume() takes one parameter, a number from 0 to 1. As a bonus, there is a complimenary method to get the current volume called getVolume(). As expected this method will return a number between 0 and 1.

You can change the volume when the player loads by calling the setVolume() method in the onTemplateLoaded() handler, though calling it in the templateReady handler would be better. Otherwise you can call the same method at any other time after the player loads. You could call it when a button is clicked, when a timer is triggered, or pretty much any other event that makes sense for your application.

I've attached a Javascript version of this setup and you can see it live here:

http://www.echostring.com/bc/setVolume_as3/
Message Edited by BC-ChrisD on 02-26-2009 05:12 PM
Christopher DeGrace
Product Manager
Contributor
dezza
Posts: 15
Registered: ‎02-16-2009
0 Kudos

Re: Controlling Player Volume with the Player APIs

Hi Chris,

 

Is it intentional that a call to setVolume() does not trigger a volumeChanged() event? That's been my experience. If I only have one volume control than I can assume that whatever I last tried to set it to is the current value, however that does seem to render the volume change event ("mediaVolumeChange") somewhat pointless. The volume change event does get dispatched once at player start up. 

 

In your example you can kind of see that the slider control within the flash player is not aware of any volume changes made via the html buttons (if it's open already) and that the slider only checks the volume when opening. That may not have been your intention but it highlights the point.

 

Just wondering if this is supposed to be the case.

 

Cheers d

Brightcove Team
BC-ChrisD
Posts: 121
Registered: ‎12-07-2008
0 Kudos

Re: Controlling Player Volume with the Player APIs

d,

 

The mediaVolumeChange event fires any time the in player volume control is used as well as when the volume is changed through the APIs with setVolume(), I just wasn't listening for that event.

 

I've updated my example to show this by adding an event listener and then just tracing a message when it occurs.

 

video.addEventListener(BCVideoEvent.VOLUME_CHANGE, onVolumeChange);

 

Does that help? If not, let me know.

Christopher DeGrace
Product Manager
Contributor
dezza
Posts: 15
Registered: ‎02-16-2009
0 Kudos

Re: Controlling Player Volume with the Player APIs

yup you are right. My event handler was not getting called because of a problem with registration - I think I assumed too much after looking at the eg. Thanks for clarifying.

 

New Member
holly750
Posts: 2
Registered: ‎08-06-2009
0 Kudos

Re: Controlling Player Volume with the Player APIs

Does this method apply to macs as well? the downloads seem to be for PC's. 

 

Thanks

 

holly  

Brightcove Team
BC-JHuebner
Posts: 109
Registered: ‎01-26-2009
0 Kudos

Re: Controlling Player Volume with the Player APIs

Yes this example works with Macs, I just viewed it in Safari 3.1.2 on MacOS 10.5.6. Are you having difficulty?

What browser is experiencing the issue?

 

John Huebner

QA 

New Member
holly750
Posts: 2
Registered: ‎08-06-2009
0 Kudos

Re: Controlling Player Volume with the Player APIs

honestly  - i'm having trouble understanding the instructions - the IT department said it looked like it was for PCs. would there be any way to get a simpler set of instructions? 
Brightcove Team
BC-JHuebner
Posts: 109
Registered: ‎01-26-2009
0 Kudos

Re: Controlling Player Volume with the Player APIs

[ Edited ]

Holly,

 

This solution only works if you add custom code. That code can be javascript in your web page or it can be built into a custom player. The example uses javascript in a web page.

 

It might be a good idea to start with the overview 

http://support.brightcove.com/en/docs/player-api-overview

 

and then look at the Javascript version of the Player API documentation. 

The useful, step by step instructions are duplicated in seperate docs for Javascript and ActionScript(Flash) so that we can give specific examples, so that is the doc that will probably be the most helpful:

http://support.brightcove.com/en/docs/using-javascript-player-api

 

Then start from zipfile in this thread, and take the following steps (borrowed from the Player API examples):
 
1) Create a Video Player instance in the Brightcove Publishing Module.

2) Make sure you've enabled the API for the player by checking "Enable ActionScript/JavaScript APIs" in the edit settings dialog for the player you just created.

3) Copy the playerID and publisherID that you find in the ActionScript snippet generated by the Experience Module when you select "get code". Update these values in the player snippet found in JavaScriptTileList.html.

4) In the Media Module, copy the ID of a playlist you wish to load. Assign this value to the PLAYLIST_ID property at the top of the JavaScriptTileList.js file.

5) Load JavaScriptTileList.html in browser.


 

I hope that helps,

 

John

Message Edited by BC-JHuebner on 08-06-2009 10:56 AM
Message Edited by BC-JHuebner on 08-06-2009 11:08 AM
Visitor
WilHarris
Posts: 4
Registered: ‎08-27-2009
0 Kudos

Re: Controlling Player Volume with the Player APIs

Hi guys,

 

I'm trying to get my head around how volume control could be set using BEML (Javascript on the page won't work for me as I want the settings to travel with the player if it is virally embedded).  

 

Am I right in thinking that I would need to create a SWF that is included in the BEML code that calls the setVolume method?   It would be lovely if volume was one of the parameters included in the BrightcoveExperience class so that it could simply be set as a param name in the HTML embed code.

 

Any suggestions as to the simplest way to implement this  gratefully accepted...

 

 

Visitor
yrox
Posts: 3
Registered: ‎09-02-2010
0 Kudos

Re: Controlling Player Volume with the Player APIs

Hi,

I am also looking for BEML example to implement 50% default volume for my players. Is it possible to do so using BEML?