live.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view>
  3. <navbar :config="config" backColor="#999999"></navbar>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view>
  6. <video id="myVideo" is-live :src="info.liveJumpUrl" style="width: 100%;" autoplay
  7. @error="videoErrorCallback" :danmu-list="danmuList" enable-danmu danmu-btn controls @fullscreenchange="fullscreenchange"></video>
  8. </view>
  9. <view class="liveTitleBox">{{info.liveTitle}}</view>
  10. <!-- #ifndef MP-ALIPAY -->
  11. <!-- <view class="uni-list uni-common-mt">
  12. <view class="uni-list-cell">
  13. <view>
  14. <view class="uni-label">弹幕内容</view>
  15. </view>
  16. <view class="uni-list-cell-db">
  17. <input v-model="danmuValue" class="uni-input" type="text" placeholder="在此处输入弹幕内容" />
  18. </view>
  19. </view>
  20. </view>
  21. <view class="uni-btn-v">
  22. <button @click="sendDanmu" class="page-body-button">发送弹幕</button>
  23. </view> -->
  24. <!-- #endif -->
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. config: {
  33. back: false,
  34. title: '身边景',
  35. color: '#1A1A1A',
  36. // backgroundColor: [1, '#fff'],
  37. backgroundColor: '#fff',
  38. statusBarFontColor: '#fff'
  39. },
  40. info:{},
  41. danmuList: [
  42. // {
  43. // text: '第 1s 出现的弹幕',
  44. // color: '#ff0000',
  45. // time: 1
  46. // },
  47. // {
  48. // text: '第 3s 出现的弹幕',
  49. // color: '#ff00ff',
  50. // time: 3
  51. // }
  52. ],
  53. danmuValue: ''
  54. }
  55. },
  56. onLoad(options) {
  57. if(options.liveId){
  58. this.getLiveInfo(options.liveId)
  59. }
  60. },
  61. onReady: function(res) {
  62. // #ifndef MP-ALIPAY
  63. this.videoContext = uni.createVideoContext('myVideo')
  64. // this.videoContext.requestFullScreen();
  65. // #endif
  66. },
  67. methods: {
  68. getLiveInfo(liveId){
  69. this.$yghttp.get(`/live/liveInfo/info/${liveId}`).then(res => {
  70. this.info = res.data;
  71. })
  72. },
  73. sendDanmu: function() {
  74. this.videoContext.sendDanmu({
  75. text: this.danmuValue,
  76. color: this.getRandomColor()
  77. });
  78. this.danmuValue = '';
  79. },
  80. videoErrorCallback: function(e) {
  81. // uni.showModal({
  82. // content: e.target.errMsg,
  83. // showCancel: false
  84. // })
  85. },
  86. fullscreenchange(e){
  87. if(e.detail.direction=='vertical'){
  88. // uni.navigateBack()
  89. }
  90. },
  91. getRandomColor: function() {
  92. const rgb = []
  93. for (let i = 0; i < 3; ++i) {
  94. let color = Math.floor(Math.random() * 256).toString(16)
  95. color = color.length == 1 ? '0' + color : color
  96. rgb.push(color)
  97. }
  98. return '#' + rgb.join('')
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. .liveTitleBox{
  105. text-align: center;
  106. margin-top: 20rpx;
  107. font-size:32rpx;
  108. }
  109. </style>