添加续播功能

master
laiiihz 5 years ago
parent 590222db63
commit 5dc5bce24a

@ -520,4 +520,7 @@ class LiveAPI {
///
static const String getLiveUsers = '/v1/live/live/user_data';
///
static const String getLiveInfo = '/v1/live/live/info';
}

@ -36,7 +36,7 @@ class _LiveBlurPageState extends State<LiveBlurPage> {
@override
void initState() {
super.initState();
_isAttention = widget.streamModel.isFollow == 1;
_isAttention = widget.streamModel?.isFollow == 1;
}
@override

@ -15,6 +15,7 @@ import 'package:recook/pages/live/live_stream/live_users_view.dart';
import 'package:recook/pages/live/live_stream/pick_view/pick_cart.dart';
import 'package:recook/pages/live/live_stream/show_goods_list.dart';
import 'package:recook/pages/live/models/live_exit_model.dart';
import 'package:recook/pages/live/models/live_resume_model.dart';
import 'package:recook/pages/live/models/live_stream_info_model.dart';
import 'package:recook/pages/live/models/topic_list_model.dart';
import 'package:recook/pages/live/tencent_im/tencent_im_tool.dart';
@ -34,7 +35,11 @@ import 'package:image_picker/image_picker.dart';
import 'package:wakelock/wakelock.dart';
class LivePage extends StatefulWidget {
LivePage({Key key}) : super(key: key);
final bool resumeLive;
///resumeLive `true`
final LiveResumeModel model;
LivePage({Key key, this.resumeLive = false, this.model}) : super(key: key);
@override
_LivePageState createState() => _LivePageState();
@ -94,6 +99,30 @@ class _LivePageState extends State<LivePage> {
onCloudVideoCreated: (controller) async {
_livePusher = await LivePusher.create();
_livePusher.startPreview(controller);
if (widget.resumeLive) {
_isStream = true;
liveItemId = widget.model.liveItemId;
_streamInfoModel =
LiveStreamInfoModel.fromLiveResume(widget.model);
_livePusher.startPush(widget.model.pushUrl);
setState(() {});
TencentIMTool.login().then((_) {
DPrint.printLongJson('用户登陆');
getLiveStreamModel(liveItemId).then((model) {
if (model == null)
Navigator.pop(context);
else {
setState(() {
_streamInfoModel = model;
});
TencentImPlugin.applyJoinGroup(
groupId: model.groupId, reason: 'enterLive');
TencentImPlugin.addListener(parseMessage);
group = TencentGroupTool.fromId(model.groupId);
}
});
});
}
},
),
),

@ -0,0 +1,140 @@
class LiveResumeModel {
int liveItemId;
String pushUrl;
String groupId;
String nickname;
String headImgUrl;
int userId;
int praise;
List<GoodsLists> goodsLists;
LiveResumeModel(
{this.liveItemId,
this.pushUrl,
this.groupId,
this.nickname,
this.headImgUrl,
this.userId,
this.praise,
this.goodsLists});
LiveResumeModel.fromJson(Map<String, dynamic> json) {
liveItemId = json['liveItemId'];
pushUrl = json['pushUrl'];
groupId = json['groupId'];
nickname = json['nickname'];
headImgUrl = json['headImgUrl'];
userId = json['userId'];
praise = json['praise'];
if (json['goodsLists'] != null) {
goodsLists = new List<GoodsLists>();
json['goodsLists'].forEach((v) {
goodsLists.add(new GoodsLists.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['liveItemId'] = this.liveItemId;
data['pushUrl'] = this.pushUrl;
data['groupId'] = this.groupId;
data['nickname'] = this.nickname;
data['headImgUrl'] = this.headImgUrl;
data['userId'] = this.userId;
data['praise'] = this.praise;
if (this.goodsLists != null) {
data['goodsLists'] = this.goodsLists.map((v) => v.toJson()).toList();
}
return data;
}
}
class GoodsLists {
int id;
String goodsName;
String brandImg;
String brandName;
int brandId;
String description;
int inventory;
int salesVolume;
String mainPhotoUrl;
String promotionName;
String originalPrice;
String discountPrice;
String commission;
List<String> tags;
int percent;
String startTime;
String endTime;
String coupon;
int isExplain;
GoodsLists(
{this.id,
this.goodsName,
this.brandImg,
this.brandName,
this.brandId,
this.description,
this.inventory,
this.salesVolume,
this.mainPhotoUrl,
this.promotionName,
this.originalPrice,
this.discountPrice,
this.commission,
this.tags,
this.percent,
this.startTime,
this.endTime,
this.coupon,
this.isExplain});
GoodsLists.fromJson(Map<String, dynamic> json) {
id = json['id'];
goodsName = json['goodsName'];
brandImg = json['brandImg'];
brandName = json['brandName'];
brandId = json['brandId'];
description = json['description'];
inventory = json['inventory'];
salesVolume = json['salesVolume'];
mainPhotoUrl = json['mainPhotoUrl'];
promotionName = json['promotionName'];
originalPrice = json['originalPrice'];
discountPrice = json['discountPrice'];
commission = json['commission'];
tags = json['tags'].cast<String>();
percent = json['percent'];
startTime = json['startTime'];
endTime = json['endTime'];
coupon = json['coupon'];
isExplain = json['isExplain'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['goodsName'] = this.goodsName;
data['brandImg'] = this.brandImg;
data['brandName'] = this.brandName;
data['brandId'] = this.brandId;
data['description'] = this.description;
data['inventory'] = this.inventory;
data['salesVolume'] = this.salesVolume;
data['mainPhotoUrl'] = this.mainPhotoUrl;
data['promotionName'] = this.promotionName;
data['originalPrice'] = this.originalPrice;
data['discountPrice'] = this.discountPrice;
data['commission'] = this.commission;
data['tags'] = this.tags;
data['percent'] = this.percent;
data['startTime'] = this.startTime;
data['endTime'] = this.endTime;
data['coupon'] = this.coupon;
data['isExplain'] = this.isExplain;
return data;
}
}

@ -1,3 +1,5 @@
import 'package:recook/pages/live/models/live_resume_model.dart';
class LiveStreamInfoModel {
String nickname;
String headImgUrl;
@ -22,6 +24,15 @@ class LiveStreamInfoModel {
this.groupId,
this.goodsLists});
LiveStreamInfoModel.fromLiveResume(LiveResumeModel model) {
this.nickname = model.nickname;
this.headImgUrl = model.headImgUrl;
this.groupId = model.groupId;
this.goodsLists =
model.goodsLists.map((e) => GoodsLists.fromJson(e.toJson())).toList();
this.id = model.liveItemId;
}
LiveStreamInfoModel.fromJson(Map<String, dynamic> json) {
nickname = json['nickname'];
headImgUrl = json['headImgUrl'];

@ -8,13 +8,16 @@
*/
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:recook/constants/api.dart';
import 'package:recook/constants/config.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/constants/styles.dart';
import 'package:recook/manager/http_manager.dart';
import 'package:recook/manager/user_manager.dart';
import 'package:recook/pages/business/business_page.dart';
import 'package:recook/pages/home/home_page.dart';
import 'package:recook/pages/live/live_stream/live_page.dart';
import 'package:recook/pages/live/models/live_resume_model.dart';
import 'package:recook/pages/live/video/add_video_page.dart';
import 'package:recook/pages/live/pages/discovery_page.dart';
import 'package:recook/pages/live/widget/live_fab_location.dart';
@ -27,6 +30,7 @@ import 'package:recook/utils/custom_route.dart';
import 'package:recook/utils/permission_tool.dart';
import 'package:recook/utils/print_util.dart';
import 'package:recook/utils/versionInfo/version_tool.dart';
import 'package:recook/widgets/alert.dart';
import 'package:recook/widgets/cache_tab_bar_view.dart';
import 'package:recook/widgets/custom_image_button.dart';
import 'package:recook/widgets/tabbarWidget/ace_bottom_navigation_bar.dart';
@ -78,6 +82,7 @@ class _TabBarWidgetState extends State<TabBarWidget>
}
_showBottomModalSheet() {
BuildContext fatherContext = context;
showModalBottomSheet(
context: context,
builder: (context) {
@ -131,7 +136,53 @@ class _TabBarWidgetState extends State<TabBarWidget>
onTap: () {
PermissionTool.haveCameraPermission().then((value) {
PermissionTool.haveAudioPermission().then((value) {
CRoute.pushReplace(context, LivePage());
GSDialog.of(context)
.showLoadingDialog(context, '加载中');
HttpManager.post(LiveAPI.getLiveInfo, {})
.then((resultData) {
GSDialog.of(context).dismiss(context);
LiveResumeModel model = LiveResumeModel.fromJson(
resultData.data['data']);
if (model.liveItemId == 0)
CRoute.pushReplace(context, LivePage());
else {
Navigator.pop(context);
showDialog(
context: context,
child: NormalTextDialog(
title: '有未完成的直播间',
content: '',
items: ['结束直播', '继续直播', '开始新直播'],
listener: (index) {
Navigator.pop(fatherContext);
switch (index) {
case 0:
HttpManager.post(LiveAPI.exitLive, {
'liveItemId': model.liveItemId,
});
break;
case 1:
CRoute.push(
fatherContext,
LivePage(
resumeLive: true,
model: model,
));
break;
case 2:
HttpManager.post(LiveAPI.exitLive, {
'liveItemId': model.liveItemId,
}).then((_) {
CRoute.pushReplace(
context, LivePage());
});
break;
}
},
),
);
}
});
});
});
},

Loading…
Cancel
Save