Video

添加 <video /> 标签,在 Kraken 内部嵌入一个 视频播放器。

快速使用

kraken_video_player 作为项目依赖添加到 pubspec.yaml 文件中。

在调用 runApp() 之前添加以下代码:

  1. import 'package:kraken_video_player/kraken_video_player.dart';
  2. void main() {
  3. KrakenVideoPlayer.initialize();
  4. runApp(MaterialApp(
  5. title: 'Navigation Basics',
  6. home: FirstRoute(),
  7. ));
  8. }

示例

  1. function setElementStyle(dom, object) {
  2. if (object == null) return;
  3. for (let key in object) {
  4. if (object.hasOwnProperty(key)) {
  5. dom.style[key] = object[key];
  6. }
  7. }
  8. }
  9. function setAttributes(dom, object) {
  10. for (const key in object) {
  11. if (object.hasOwnProperty(key)) {
  12. dom.setAttribute(key, object[key]);
  13. }
  14. }
  15. }
  16. const container1 = document.createElement('div');
  17. setElementStyle(container1, {
  18. height: '500px',
  19. });
  20. document.body.appendChild(container1);
  21. const video = document.createElement('video');
  22. setElementStyle(video, {
  23. width: '750px',
  24. height: '400px',
  25. });
  26. setAttributes(video, {
  27. autoPlay: true,
  28. src:
  29. 'https://videocdn.taobao.com/oss/ali-video/1fa0c3345eb3433b8af7e995e2013cea/1458900536/video.mp4',
  30. });
  31. video.addEventListener('canplay', () => {
  32. console.log('vide can play');
  33. });
  34. container1.appendChild(video);
  35. const pauseBtn = document.createElement('div');
  36. pauseBtn.appendChild(document.createTextNode('pause button'));
  37. pauseBtn.addEventListener('click', () => {
  38. video.pause();
  39. });
  40. container1.appendChild(pauseBtn);
  41. const playBtn = document.createElement('div');
  42. playBtn.appendChild(document.createTextNode('playBtn button'));
  43. playBtn.addEventListener('click', () => {
  44. video.play();
  45. });
  46. container1.appendChild(playBtn);

API

参考: 链接