tltest.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div>
  3. <br />
  4. <div id="pusher" style="width:300px;height:400px;background-color:#000000;margin:auto"></div>
  5. <br />
  6. <div style="text-align:center; margin:auto;">
  7. <input id="path" type="text" value="" placeholder="请输入直播服务器地址(rtmp)" />
  8. <button id="pp" v-on:click="ppPusher()">开始</button>
  9. </div>
  10. <div class="button" v-on:click="switchCamera()">切换摄像头</div>
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. bstart: false,
  18. pusher: null,
  19. };
  20. },
  21. created() {
  22. document.addEventListener('plusready', this.plusReady, false);
  23. },
  24. methods: {
  25. switchCamera() {
  26. this.pusher.switchCamera();
  27. },
  28. plusReady() {
  29. // 创建直播推流控件
  30. this.pusher = new plus.video.LivePusher('pusher', {
  31. url: 'rtmp://live.liaoningdoupo.com/live/',
  32. });
  33. // 监听状态变化事件
  34. this.pusher.addEventListener(
  35. 'statechange',
  36. function(e) {
  37. console.log('statechange: ' + JSON.stringify(e));
  38. },
  39. false
  40. );
  41. },
  42. ppPusher() {
  43. if (this.bstart) {
  44. this.pusher.stop();
  45. this.bstart = false;
  46. } else {
  47. var path = document.getElementById('path').value;
  48. if (path && path.length > 0) {
  49. this.pusher.setOptions({ url: path });
  50. this.pusher.start();
  51. this.bstart = true;
  52. } else {
  53. plus.nativeUI.toast('请输入直播服务器地址');
  54. }
  55. }
  56. var pp = document.getElementById('pp');
  57. pp.innerText = this.bstart ? '停止' : '开始';
  58. },
  59. },
  60. };
  61. </script>
  62. <style scoped>
  63. input {
  64. width: 70%;
  65. font-size: 16px;
  66. padding: 0.2em 0.2em;
  67. border: 1px solid #00b100;
  68. -webkit-user-select: text;
  69. }
  70. .button,
  71. button {
  72. width: 20%;
  73. margin: 6px 0 6px 6px;
  74. font-size: 16px;
  75. color: #fff;
  76. background-color: #00cc00;
  77. border: 1px solid #00b100;
  78. padding: 0.2em 0em;
  79. -webkit-border-radius: 5px;
  80. border-radius: 5px;
  81. }
  82. </style>