The settings for common Web Player features can vary depending on the playback mode, playback method, and browser environment. This topic provides usage examples for basic Web Player features.
Common settings
The Web Player software development kit (SDK) requires a cross-domain access configuration to play FLV and HLS videos. For more information about how to configure cross-domain access, see Configure cross-domain access.
If cross-domain access is not configured, the browser reports the following error during playback:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
After you enter full screen mode, you must set the input to use absolute positioning to bring up the soft keyboard.
API call rules
The basic features of the Web Player are implemented through properties or APIs.
For more information about the properties and APIs, see Aliplayer API reference.
The rules for calling APIs are as follows:
Call the API in the callback function of the player constructor. The following code provides an example:
var player = new Aliplayer({},function(player) {
player.setSpeed(2);
});Control playback
The Web Player supports operations such as starting playback from a specific time and pausing playback.
Start playback from a specific time
This feature jumps to a specific time for playback. It is implemented by the seek API. The following code provides an example:
// time is the specified time in seconds.
player.seek(time)Pause playback
This feature pauses video playback. It is implemented by the pause API. The following code provides an example:
player.pause()To display the large play button, pass the true parameter. For example: player.pause(true).
Destroy the player
This feature destroys the player instance. It is implemented by the dispose API. The following code provides an example:
player.dispose()Set the display mode
Supported on desktop and iOS browsers.
Supported on Android (Chrome and Firefox).
This feature is not supported in WeChat and most browsers because they intercept video playback and use their own players.
Rotate
This feature rotates the video by a specified angle. It is implemented by the setRotate API. After setting the rotation, you can also query the rotation angle. The following code provides an example:
// Set the rotation angle. A positive value for <angle> indicates clockwise rotation, and a negative value indicates counterclockwise rotation. For example, player.setRotate(180) rotates the video 180 degrees clockwise.
player.setRotate(<angle>)
// Get the rotation angle.
player.getRotate()Mirror
This feature supports horizontal and vertical mirroring. It is implemented by the setImage API. The following code provides an example:
// Horizontal mirror
player.setImage('horizon')
// Vertical mirror
player.setImage('vertical')In addition, the Web Player provides the videoHeight and videoWidth properties to set the height and width of the video. The height and width are typically set to values smaller than the container dimensions to prevent the video from overflowing the parent container during rotation and mirroring. The following code provides an example:
width: '100%', // Container size
height: '100%', // Container size
videoHeight:"200px", // Video heightGet playback information
The Web Player lets you retrieve the current playback progress and total duration.
Get the current playback progress
This feature retrieves the current playback time. It is implemented by the getCurrentTime API. The following code provides an example:
// The API returns the time in seconds.
player.getCurrentTime()Get the playback duration
This feature retrieves the total duration of the video. You can retrieve the duration only after the video is loaded, which occurs after the play event. It is implemented by the getDuration API. The following code provides an example:
player.getDuration()Listen for playback status
This feature monitors the player's status. It is implemented by the getStatus API. The return values include the following:
init: Initialized.
ready: Ready.
loading: Loading.
play: Play.
pause: Paused.
playing: Playing.
waiting: Waiting for buffer.
error: Error.
ended: Ended.
The following code provides an example:
player.getStatus()Set the volume
Setting the volume includes volume adjustment and muting.
Because the video.volume property is read-only in iOS and some Android systems, the getVolume and setVolume methods provided by ApsaraVideo Player SDK for web do not work on iOS and some Android systems.
Adjust the volume
This feature adjusts the volume level. It is implemented by the setVolume API. After setting the volume, you can also retrieve the volume information. The following code provides an example:
// The value of volume is a real number between 0 and 1.
player.setVolume(0)
// Get the volume information.
player.getVolume()Mute Settings
This feature mutes a video that is playing. It is implemented by the mute API. The following code provides an example:
// Mute the video
player.mute();
// Unmute the video
player.unMute();Playback speed control
The default UI of the Web Player SDK includes a playback speed control feature. Viewers can select a playback speed from the interface. If you use a custom UI, you can implement the playback speed control feature using the setSpeed API.
To disable the playback speed setting, see the Aliplayer API Reference for the description of setSpeed.
For example:
// The following example sets the playback speed to twice the current speed.
player.setSpeed(2)Multi-definition playback
This feature allows multi-definition playback by setting the addresses of multiple definition streams.
If you use the VID+PlayAuth method for playback, no extra settings are required. The Web Player SDK retrieves the definition list from the ApsaraVideo VOD service. Viewers can click the Settings button in the control bar of the playback interface to view the definition list.
NoteWhen using the VID+PlayAuth method, you can set the `format` property in H5 playback mode to select the MP4 or MP3 format. The default format is MP4.
If you use the URL playback method by setting the source property, you must specify the addresses of multiple definition streams as key-value pairs in the source property's JSON structure. After you apply the settings, viewers can click the Settings button in the control bar of the playback interface to view the definition list.
You can customize the UI of the definition list using the definition component. For code examples, see Feature Demo.
When using the URL playback method, the key-value pairs in the JSON structure for the `source` property include the following:
"OD": "<Original Quality URL>"
"FD": "<Low Definition URL>"
"LD": "<Standard Definition URL>"
"SD": "<High Definition URL>"
"HD": "<Ultra High Definition URL>"
"2K": "<2K URL>"
"4K": "<4K URL>"The following code provides an example of how to set definitions for the URL playback method:
// The example sets the addresses for Ultra High Definition and High Definition.
source:'{"HD":"http://******/player/hdexample.mp4","SD":"http://******/player/sdexample.mp4"}'The Web Player also supports the `qualitySort` property to sort the definitions in ascending or descending order.
desc: Sorts in descending order (from highest to lowest).
asc: Sorts in ascending order (from lowest to highest).
The player remembers the user's definition selection. When the user reopens the video, the player prioritizes the last selected definition. If the last selected definition is not available, the player selects a lower definition by default.
If the selected definition cannot be played, the player automatically switches to the next available definition and displays a prompt. This is supported only in H5.
Loop playback
The Web Player supports loop playback by setting the rePlay property or by listening for the ended event.
Example of setting the rePlay property
rePlay:trueExample of listening for the ended event
player.on('ended',function(){
player.replay()
})Mobile gesture controls
The Web Player is optimized for small screens on mobile devices and includes a progress bar that is easier to drag. It also provides two mobile-specific features: long-press for fast-forward and double-tap to seek.
Long-press speed control
By default, the long-press for fast-forward feature is enabled on mobile devices. You can long-press any area of the player except the progress bar for about 0.5 seconds to start fast-forwarding. Release your finger to resume the original playback speed.
To disable this feature, set the longPressFastForward: false parameter. For more information, see Aliplayer API reference.
Double-tap to seek
By default on mobile devices, the web player includes a double-click feature to fast forward and fast backward. Double-clicking the left one-third of the playback screen skips forward 10 seconds, and double-clicking the right one-third skips backward 10 seconds.
To disable this feature, set the dbClickSkip: false parameter. For more information, see Aliplayer API reference.