VideoContext

解释: swan.createVideoContext 的返回值

# 示例

扫码体验
重新加载
请使用百度APP扫码

# 图片示例

# 代码示例

    <view class="wrap">
        <video id="myVideo" enable-danmu="true" src="https://b.bdstatic.com/swan-temp/940fe716b0eaad38f47b209d61657490.mp4"></video>
        <button type="primary" bindtap="play">play</button>
        <button type="primary" bindtap="stop">stop</button>
        <button type="primary" bindtap="pause">pause</button>
        <button type="primary" bindtap="seek">seek</button>
        <button type="primary" bindtap="sendDanmu">sendDanmu</button>
        <button type="primary" bindtap="fullScreen">requestFullScreen</button>
        <button type="primary" data-set="0.75" bindtap="playbackRate">点击0.75倍速播放</button>
        <button type="primary" data-set="1.0" bindtap="playbackRate">点击1.0倍速播放</button>
        <button type="primary" data-set="1.25" bindtap="playbackRate">点击1.25倍速播放</button>
        <button type="primary" data-set="1.5" bindtap="playbackRate">点击1.5倍速播放</button>
        <button type="primary" data-set="2.0" bindtap="playbackRate">点击2.0倍速播放</button>
    </view>
    
    Page({
        onLoad() {
            this.videoContext = swan.createVideoContext('myVideo');
            console.log('这是一个VideoContext的实例', this.videoContext);
        },
        sendDanmu() {
            this.videoContext.sendDanmu({
                text: '这是一条弹幕',
                color: '#f60'
            });
            swan.showToast({
                title: '发送成功',
                icon: 'none'
            });
        },
        play() {
            this.videoContext.play();
            swan.showToast({
                title: 'play',
                icon: 'none'
            });
        },
        stop() {
            this.videoContext.stop();
            swan.showToast({
                title: 'stop',
                icon: 'none'
            });
        },
        pause() {
            this.videoContext.pause();
            swan.showToast({
                title: 'pause',
                icon: 'none'
            });
        },
        seek() {
            this.videoContext.seek(10);
            swan.showToast({
                title: '跳转到10s处',
                icon: 'none'
            });
        },
        fullScreen() {
            this.videoContext.requestFullScreen();
        },
        playbackRate(e) {
            console.log('当前倍速', +e.target.dataset.set);
            swan.showToast({
                title: '当前倍速为' + +e.target.dataset.set,
                icon: 'none'
            });
            this.videoContext.playbackRate(+e.target.dataset.set);
        }
    });
    

    # 错误码

    # Android

    错误码 说明
    202 解析失败,请检查参数是否正确
    1001 执行失败

    # iOS

    错误码 说明
    202 解析失败,请检查参数是否正确