All Products
Search
Document Center

Mobile Platform as a Service:Video

Last Updated:Jul 27, 2023

my.createVideoContext

You can call this interface to input video id and return a videoContext. video ID refers to the ID attribute customized by the developer in the corresponding video tab.

You can operate a video component through videoContext.

Note

Version requirement: Base library V1.14.1 or later versions.

Sample code

Write the following code to name a video id in .axml file. video ID refers to the ID attribute customized by the developer in the corresponding video tab, such as myVideo in the following code.

<view>

<! -- If the type of onPlay is EventHandle, the play event will be triggered when you start or continue playing. -->
  <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>

Write the following code in the .js file:

Page({
  data: {

  // src is the resource address of the video you want to play. Src supports apFilePath: 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

-

Play.

pause

None

-

Pause.

stop

None

-

Stop.

seek

position

Number

Redirect to the specific position. The unit is second.

requestFullScreen

direction

Number

Enter full screen mode.

  • 0 is vertical screen.

  • 90 is horizontal screen.

  • -90 is reversed horizontal screen.

exitFullScreen

None

-

Exit full screen mode.

showStatusBar

None

-

Show status bar. The method only works in full screen mode in iOS App.

hideStatusBar

None

-

Hide status bar. The method only works in full screen mode in iOS App.

mute

ison

Boolean

Switch to mute status.

playbackRate

rate

Number

Set playback rate (0.5 ≤ rate ≤ 2.0). This method is not supported by mPaaS currently.

Note

To use iOS full screen, you need to check Landscape Left and Landscape Right in Xcode> General> Deployment Info, as shown below.

device orientation