_Video

视频播放类(移动平台可用) 全部展开

静态属性展开

  • + Failed: uint

    加载失败。

  • + Loading: uint

    正在加载。

  • + Ready: uint

    可播放。

只读属性展开

  • + currentTime : float

    视频当前播放时间。

    • 示例

       print(video.currentTime)
  • + duration : float

    视频总长度,只在加载状态是Ready的情况下有效。

    • 示例

       print(video.duration)
  • + isPlaying : bool

    视频是否正在播放。

    • 示例

       print(video.isPlaying)
  • + state : uint

    获取视频加载状态。

    • 示例

       print(video.state)

构造方法展开

  • + function _Video( resname : string ) : _Video
    • 参数
    • resname:视频资源名或者http://开头的url地址
    • 示例

       video = _Video.new(‘http://www.fancy3d.com/samp/sample.mp4’)

公共方法展开

  • + function hideText()

    停止播放视频。

    • 示例

       local video = _Video.new('http://www.fancy3d.com/samp/sample.mp4')
      video:hideText()
  • + function pause()

    暂停视频。

    • 示例

       local video = _Video.new('http://www.fancy3d.com/samp/sample.mp4')
      video:pause()
  • + function play()

    播放视频。

    • 示例

       local video = _Video.new('http://www.fancy3d.com/samp/sample.mp4')
      video:play()
  • + function showText(text : string, x : uint, y : uint, size : uint, color : uint)

    显示文本。

    • 参数

      text : 文本内容
      x : 文本位置X坐标
      y : 文本位置Y坐标
      size : 字体大小
      color : 颜色
    • 示例

       local video = _Video.new('http://www.fancy3d.com/samp/sample.mp4')
      video:showText('welcome', 10, 10, 10, _Color.Red)
  • + function stop()

    停止播放视频。

    • 示例

       local video = _Video.new('http://www.fancy3d.com/samp/sample.mp4')
      video:stop()

代码示例

    local video = _Video.new('http://www.fancy3d.com/samp/sample.mp4')
    local state = _Video.Loading

    _app:onIdle(function()
        _rd:drawLine(0, _rd.h/2, _rd.w, _rd.h/2, _Color.Red)
        _rd:drawLine(_rd.w/2, 0, _rd.w/2, _rd.h, _Color.Red)
        state = video.state
    end)

    local click = function(x,y)
        if x < _rd.w/2 and y < _rd.h/2 then
            if state == _Video.Loading then
                print('video is loading')
            elseif state == _Video.Ready then
                print('video duration is ', video.duration)
                video:play()
            elseif state == _Video.Failed then
                print('video is unknown')
            end
        end

        if x >= _rd.w/2 and y < _rd.h/2 and video.isPlaying then
            video:pause()
            print('current time is ', video.currentTime)
        end

        if y >= _rd.h/2 then
            video:stop()
        end
    end

    if _sys.os == 'ios' or _sys.os == 'android' then
        _app:onTouchBegin(click)
    else
        _app:onMouseDown(click)
    end
问题反馈(登录才可以发表哦!)