All Products
Search
Document Center

Mobile Platform as a Service:Video

Last Updated:Jan 22, 2026

This document describes how to use my.createVideoContext.

my.createVideoContext

This API accepts a video ID and returns a videoContext object. The video ID is a custom ID property that a developer assigns to the corresponding video tag.

You can use the videoContext object to control a video component.

Version requirements: Supported on base libraries 1.14.1 and later.

Code sample

In the .axml file, add the following code to assign a custom ID to the video tag. For example, the ID is myVideo in the code below.

<view>

<!-- onPlay is of the EventHandle type. It triggers the play event when playback starts or resumes. -->
  <video id="myVideo" src="{{src}}" onPlay="{{onPlay}}" enableNative="{{true}}"></video>
   <button type="default" size="defaultSize" onTap="play"> Play </button>
   <button type="default" size="defaultSize" onTap="pause"> Pause </button>
   <button type="default" size="defaultSize" onTap="stop"> stop </button>
   <button type="default" size="defaultSize" onTap="seek"> seek </button>
   <button type="default" size="defaultSize" onTap="requestFullScreen"> requestFullScreen </button>
   <button type="default" size="defaultSize" onTap="exitFullScreen"> exitFullScreen </button>
   <button type="default" size="defaultSize" onTap="mute"> mute </button>
</view>

In the .js file, add the following code:

Page({
  data: {

  // src is the resource address of the video to be played. src supports apFilePath, for example, https://resource/xxx.video.
    src: "http://flv.bn.netease.com/tvmrepo/2012/7/C/7/E868IGRC7-mobile.mp4",
  },
  onLoad() {
    this.videoContext = my.createVideoContext('myVideo');
  },

  play() {
    this.videoContext.play();
  },

  pause() {
    this.videoContext.pause();
  },

  stop() {
    this.videoContext.stop();
  },

  seek() {
    this.videoContext.seek(100);
  },

  requestFullScreen() {
    this.videoContext.requestFullScreen({
      direction: 0
    });
  },

  exitFullScreen() {
    this.videoContext.exitFullScreen();
  },

  mute() {
    this.videoContext.mute(false);
  },


});

videoContext methods

Method

Parameter

Type

Description

play

None

-

Plays the video.

pause

None

-

Pause

stop

None

-

Stop

seek

position

Number

Seeks to a specified position. The unit is seconds (s).

requestFullScreen

direction

Number

Enters full screen.

  • 0: Normal portrait mode.

  • 90: Landscape mode.

  • -90: Reverse landscape mode.

exitFullScreen

None

-

Exits full screen.

showStatusBar

None

-

Shows the status bar. This is valid only in full screen mode on iOS.

hideStatusBar

None

-

Hides the status bar. This is valid only in full screen mode on iOS.

mute

ison

Boolean

Toggles the mute state.

playbackRate

rate

Number

Sets the playback speed (0.5 ≤ rate ≤ 2.0). mPaaS does not support this method.

Note

To use full screen mode on iOS, check Landscape Left and Landscape Right in Xcode > General > Deployment Info, as shown in the following figure.

device orientation