当用户购买成功以后,就可以观看此视频了。
    代码目录:src/pages/video/index.vue
    需求文档:https://www.yuque.com/xiumubai/fe/exlz8q

    用户刚进入视频播放页面的时候,视频播放地址有两种情况

    • 点击去学习进入,这时候默认播放的视频就是第一条
    • 点击某个章节进入,这时候默认播放的视频就是点击的这一条

    只需要拿到url当中的videoSourceId即可,另外还需加拿到章节信息

    1. <script>
    2. import courseService from "@/services/course";
    3. export default {
    4. data() {
    5. return {
    6. options: {},
    7. /** 章节列表 */
    8. chapterList: [],
    9. /** 课程信息 */
    10. course: {},
    11. /** 视频信息 */
    12. video: {},
    13. };
    14. },
    15. onLoad(option) {
    16. console.log("options", option);
    17. this.options = option;
    18. this.getCourseDetail();
    19. this.getVideoUrl(option.videoSourceId);
    20. },
    21. methods: {
    22. async getCourseDetail() {
    23. try {
    24. const res = await courseService.courseDetail({
    25. id: this.options.id,
    26. // id: '1192252213659774977',
    27. });
    28. this.chapterList = res.data.chapterList;
    29. this.course = res.data;
    30. } catch (e) {
    31. console.log("e", e);
    32. }
    33. },
    34. async getVideoUrl(videoSourceId) {
    35. console.log("videoid", videoSourceId);
    36. try {
    37. const res = await courseService.getVideoSource({
    38. videoSourceId,
    39. });
    40. console.log("res", res);
    41. if (res.code == 200) {
    42. this.viedeo = res.data;
    43. } else {
    44. uni.showToast({
    45. title: res.message,
    46. icon: "error",
    47. });
    48. }
    49. } catch (e) {
    50. console.log("e", e);
    51. }
    52. },
    53. videoErrorCallback(e) {
    54. uni.showModal({
    55. content: e.target.errMsg,
    56. showCancel: false,
    57. });
    58. },
    59. },
    60. };
    61. </script>

    视频播放控件

    1. <video
    2. class="video"
    3. src="https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/%E7%AC%AC1%E8%AE%B2%EF%BC%88uni-app%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D%EF%BC%89-%20DCloud%E5%AE%98%E6%96%B9%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B@20200317.mp4"
    4. @error="videoErrorCallback"
    5. :poster="course.course.cover"
    6. object-fit="fill"
    7. controls
    8. page-gesture
    9. enable-play-gesture
    10. ></video>