1.0.3 • Published 8 years ago

flashvideo v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

flashvideo

a tiny library used to publish / play rtmp streams.

usage

/**
 * xdyVideo 创建Flash窗口对象
 * domEleId 界面DOM的Id
 * width 窗口对象宽度,建议100% 由容器决定
 * height 窗口对象高度,建议100% 由容器决定
 * ready_callback_function flash窗口对象创建完毕的回调函数[异步],只有该方法通知创建成功,才能向窗口对象发命令消息
 * msg_callback_function flash消息处理结果通知
 */

import xdyVideo from 'xdyVideo.js';

let publishFlash = null;
let playFlash = null;

// publish
function publishVideo() {
  const sendPublishCommand = function () {
    const msg = JSON.stringify({
      type: 10,
      data: {
        // video&audio
        video: true,
        audio: true,

        // onlyaudio
        // video: true,
        // audio: false
        url: 'rtmp://123.56.205.116:1935/live/alexwang'
      }
    });
    publishFlash._js2native(msg);
  }

  if (publishFlash) {
    return sendPublishCommand();
  }

  xdyVideo(
    'publish',
    '100%',
    '100%',
    function (error, newPublishFlash) {
      console.log(error);
      if (error) {
        return console.error(error);
      }

      // 保存Flash窗口对象,对象窗口创建不易,不要频繁创建,下次调用优先判断该对象是否存在
      publishFlash = newPublishFlash;

      sendPublishCommand();
    },
    function (msg) {
      console.log('[publish] native 2 js', msg);
    }
  )
}

// play
function playVideo() {
  const sendPlayCommand = function () {
    const msg = JSON.stringify({
      type: 2,
      data: {
        url: 'rtmp://123.56.205.116:1935/live/alexwang'
      }
    });
    playFlash._js2native(msg);
  }

  if (playFlash) {
    return sendPlayCommand();
  }

  xdyVideo(
    'play',
    '100%',
    '100%',
    function createPlayReady(error, playflash) {
      if (error) {
        return console.error(error);
      }

      // 保存Flash窗口对象,对象窗口创建不易,不要频繁创建,下次调用优先判断该对象是否存在
      playFlash = playflash;

      sendPlayCommand();
    },
    function (msg) {
      console.log(' [play] native 2 js', msg);
    }
  )
}

// 打开/关闭视频一致的
function stop() {
  const msg = JSON.stringify({
    type: 5
  });
  publishFlash._js2native(msg);
  playFlash._js2native(msg);
}

// for test purposes
publishVideo();

playVideo();

setTimeout(stop, 5000);
1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago