|
//
// liveViewModel.m
// ThePaperHD
//
// Created by scar1900 on 15/7/2.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "liveViewModel.h"
#define getLiveInfoTag 100
#define getCommentInfoTag 101
#define getAskInfoTag 102
#define loadMoreTag 103
#define liveTitleHeight isPad?@"100":@"90"
#define topDateHeight isPad?@"45":@"35"
#define topTitlePadding isPad?@"36":@"24"
#define topTitleFont 18.f
#define lineSpace isPad?@"8":@"10"
#define contentPadding isPad?@"12":@"25"
#define videoDescFont 15.f
#define videoSizeHight isPad?@"300":@"150"
#define videoPadding isPad?@"10":@"7"
#define videoBottomPadding isPad?@"40":@"20"
#define cellHeightScale isPad?@"1.1":@"1"
#define imageLineSpace isPad?@"13":@"7"
#define paragraphSpace isPad?@"12":@"20"
#define imageDescWidth isPad?(float)1060/2:(float)(rect_screen.size.width-60)
@interface liveViewModel() <RemoteDelegate,TPMovieContentDelegate> {
CGFloat contentWidth;
UIView *videoSuperView;
}
@property(nonatomic, strong)liveDetailPageVO *livePageBO;
@property(nonatomic, strong)liveInfoBO *liveInfoBO;
@end
@implementation liveViewModel
@synthesize delegate;
@synthesize livePageBO = _livePageBO;
@synthesize liveInfoBO = _liveInfoBO;
-(instancetype)init {
self = [super init];
if (self) {
if (isPad) {
contentWidth = 1060/2;
}else {
contentWidth = rect_screen.size.width-50-10;
}
}
return self;
}
#pragma mark - set and get method
- (void)setLivePageBO:(liveDetailPageVO *)pageBO {
_livePageBO = pageBO;
if([self.delegate respondsToSelector:@selector(getLiveDetailPageData:)]) {
[self.delegate getLiveDetailPageData:pageBO];
}
}
- (void)setLiveInfoBO:(liveInfoBO *)infoBO {
_liveInfoBO = infoBO;
if ([self.delegate respondsToSelector:@selector(getLiveInfo:)]) {
[self.delegate getLiveInfo:infoBO];
}
}
#pragma mark - public method && private method
- (void)remoteAction {
if ([self.delegate respondsToSelector:@selector(startHudAnimation)]) {
[self.delegate startHudAnimation];
}
NSDictionary *dic = @{@"c":self.nodeId};
[Remote doJsonAction:getLiveInfoTag
requestUrl:liveDetailPageURL
parameter:dic
delegate:self];
NSDictionary *dic1 = @{@"ot":@"2",@"c":self.nodeId};
/**
* bug:5084(直播的追问互动列表不显示互动数)
*/
[Remote doJsonAction:getCommentInfoTag
requestUrl:contentCommentURL
parameter:dic1
delegate:self];
[Remote doJsonAction:getAskInfoTag
requestUrl:contentAskURL
parameter:dic1
delegate:self];
}
- (void)remotePullMethod {
NSDictionary *dic = @{@"n":self.nodeId};
[Remote doJsonAction:getLiveInfoTag
requestUrl:liveDetailPageURL
parameter:dic
delegate:self];
}
- (void)remotePullLoadMethod:(NSString*)nextUrl{
[Remote doJsonAction:loadMoreTag
requestUrl:nextUrl
parameter:nil
delegate:self];
}
- (void)getTableDataSourceWithLivePageData:(liveDetailPageVO*)pageBO
completion:(void (^)(NSMutableArray* dataSource,
NSMutableArray *sectionTitleList,
NSMutableArray *heightList,
NSString *nextUrl))completion{
self.liveInfoBO = setJsonDicToDataModel(pageBO.liveInfo, [liveInfoBO class]);
NSMutableArray *tempDataList = [NSMutableArray array];
NSMutableArray *heightList = [NSMutableArray array];
NSMutableArray *sectionTitleList = [NSMutableArray array];
//直播标题和banner
[tempDataList addObject:self.liveInfoBO];
[heightList addObject:liveTitleHeight];
[sectionTitleList addObject:@""];
NSMutableArray *topList = [NSMutableArray arrayWithArray:pageBO.topList];
if (topList && topList.count > 0) {
NSMutableArray *topContentList = [NSMutableArray array];
NSMutableArray *topSectionHeightList = [NSMutableArray array];
[sectionTitleList addObject:@""];
[topList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
liveContBO *liveCont = setJsonDicToDataModel(obj, [liveContBO class]);
NSString *date = [liveCont.pubTime stringByAppendingString:[NSString stringWithFormat:@" %@",liveCont.pubDate]];
NSDictionary *topDate = @{@"type":@"topDate",@"date":date};
[topContentList addObject:topDate];
[topSectionHeightList addObject:topDateHeight];
NSString *contTitle = liveCont.name;
NSAttributedString *attributedString = getLineSpaceAttributedString(contTitle,
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
NSDictionary *titleDic = @{@"title":attributedString,@"type":@"topTitle"};
[topContentList addObject:titleDic];
// CGFloat titleHeight = returnTextHeightWithRTLabel(contTitle,
// contentWidth,
// appFont(topTitleFont, NO),
// [iphoneLineSpaceAndParaSpace returnLevel5LineSpace])+[iphoneLineSpaceAndParaSpace liveColumSpace];
CGFloat titleHeight = 10 + heightForAttributeStringWithLabel(attributedString, contentWidth, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO))+[iphoneLineSpaceAndParaSpace liveColumSpace];
[topSectionHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
[self addContentToDataList:topContentList heightArray:topSectionHeightList liveCont:liveCont isTop:YES];
}];
[tempDataList addObject:topContentList];
[heightList addObject:topSectionHeightList];
}
NSMutableArray *contentDataList = [NSMutableArray arrayWithArray:pageBO.dateList];
if (contentDataList && contentDataList.count>0) {
[contentDataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *date = obj[@"pubDate"];
NSString *currStr = StringFromDate([NSDate date], @"YYYY-MM-dd");
// NSString *currStr = @"2014-07-22";
if ([currStr isEqualToString:date]) {
date = @"";
}
[sectionTitleList addObject:date];
NSArray *sectionContent = obj[@"contList"];
NSMutableArray *contentSectionHeightList = [NSMutableArray array];
NSMutableArray *contentList = [NSMutableArray array];
[sectionContent enumerateObjectsUsingBlock:^(NSDictionary* liveContDic, NSUInteger index, BOOL *stoped) {
liveContBO *liveCont = setJsonDicToDataModel(liveContDic, [liveContBO class]);
NSString *contentDate = liveCont.pubTime;
NSString *contTitle = liveCont.name;
NSAttributedString *attributedString = getLineSpaceAttributedString(contTitle,
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
NSDictionary *titleDic = @{@"title":attributedString,@"date":contentDate,@"type":@"contentTitle"};
[contentList addObject:titleDic];
// CGFloat titleHeight = returnTextHeightWithRTLabel(contTitle, contentWidth, appFont(18, NO), 8)+36;
CGFloat titleHeight = 10 + heightForAttributeStringWithLabel(attributedString, contentWidth, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO))+[iphoneLineSpaceAndParaSpace liveColumSpace];
[contentSectionHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
[self addContentToDataList:contentList heightArray:contentSectionHeightList liveCont:liveCont isTop:NO];
}];
[tempDataList addObject:contentList];
[heightList addObject:contentSectionHeightList];
}];
}
if (completion) {
completion(tempDataList,sectionTitleList,heightList,pageBO.nextUrl);
}
}
- (void)getMoreFootData:(NSMutableArray *)sourceList
responseData:(id)responsData
heightList:(NSMutableArray*)heightList
titleList:(NSMutableArray*)titleList
completion:(void (^)(NSMutableArray* dataSource,
NSMutableArray *sectionTitleList,
NSMutableArray *heightList,
NSString *nextUrl))completion{
NSMutableArray *tempList = [NSMutableArray arrayWithArray:sourceList];
NSArray *array = responsData[@"dateList"];
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *date = obj[@"pubDate"];
// if(![sectionTitleHeightList[sectionTitleHeightList.count -1] isEqualToString:date]){
// [sectionTitleHeightList addObject:date];
// }
NSArray *sectionContent = obj[@"contList"];
NSMutableArray *contentList = [NSMutableArray array];
NSMutableArray *sectionHeightArray = [NSMutableArray array];
NSMutableArray *forwardDataArray = tempList[tempList.count -1];
NSMutableArray *forwardHeightArray = heightList[heightList.count -1];
[sectionContent enumerateObjectsUsingBlock:^(id obj0, NSUInteger idx0, BOOL *stop0) {
liveContBO *liveContent = setJsonDicToDataModel(obj0, [liveContBO class]);
NSString *contentDate = liveContent.pubTime;
NSString *contTitle = liveContent.name;
NSAttributedString *attributedString = getLineSpaceAttributedString(contTitle,
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
NSDictionary *titleDic = @{@"title":attributedString,@"date":contentDate,@"type":@"contentTitle"};
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, rect_screen.size.width-60, 0)];
label.font = appFont(TEXT_TWO_LEVELSIZE, NO);
label.lineBreakMode = NSLineBreakByCharWrapping;
label.numberOfLines = 0;
label.text = contTitle;
// CGFloat titleHeight = [label sizeThatFits:CGSizeMake(rect_screen.size.width-60, CGFLOAT_MAX)].height+20.f;
CGFloat titleHeight = 10 + heightForAttributeStringWithLabel(attributedString, contentWidth, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO))+[iphoneLineSpaceAndParaSpace liveColumSpace];
if ([liveContent.pubDate isEqualToString:titleList[titleList.count-1]]) {
[forwardHeightArray addObject:[NSString stringWithFormat:@"%f",titleHeight]];
[forwardDataArray addObject:titleDic];
[self addContentToDataList:forwardDataArray heightArray:forwardHeightArray liveCont:liveContent isTop:NO];
}else{
[sectionHeightArray addObject:[NSString stringWithFormat:@"%f",titleHeight]];
[contentList addObject:titleDic];
[self addContentToDataList:contentList heightArray:sectionHeightArray liveCont:liveContent isTop:NO];
}
}];
if([titleList[titleList.count -1] isEqualToString:date]){
[tempList replaceObjectAtIndex:tempList.count-1 withObject:forwardDataArray];
[heightList replaceObjectAtIndex:heightList.count-1 withObject:forwardHeightArray];
}else{
[titleList addObject:date];
[tempList addObject:contentList];
[heightList addObject:sectionHeightArray];
}
}];
if (tempList && tempList.count >0) {
sourceList = [NSMutableArray arrayWithArray:tempList];
}
if (completion) {
completion(sourceList,titleList,heightList,responsData[@"nextUrl"]);
}
}
- (void)adVideoInView:(UIView*)view
videoFrame:(CGRect)videoFrame
videoData:(videoObjectBO*)videoBO {
if (self.moviePlayerController) {
return;
}
// self.moviePlayerController = [[TPMovieContent alloc] initWithFrame:videoFrame contentUrl:[NSURL URLWithString:videoBO.url]];
NSMutableDictionary *urlDic = [NSMutableDictionary dictionary];
[urlDic setObject:@"http://recordcdn.quklive.com:80/broadcast/activity/9449104178212910/record.m3u8" forKey:@"standard"];
[urlDic setObject:@"http://recordcdn.quklive.com:80/broadcast/activity/9447077198828974/record.m3u8" forKey:@"high"];
self.moviePlayerController = [[TPMovieContent alloc] initWithFrame:videoFrame contentUrlDic:urlDic];
self.moviePlayerController.delegate = self;
[KEY_WINDOW addSubview:self.moviePlayerController.view];
[self.delegate turnToright];
}
- (void)playFinish {
[self closeHandler];
}
- (void)addContentToDataList:(NSMutableArray *)contentArray
heightArray:(NSMutableArray*)heightArray
liveCont:(liveContBO*)liveCont
isTop:(BOOL)isTop{
NSArray *imageList = liveCont.images; //视频
NSArray *videoList = liveCont.videos;
if (videoList.count > 0) {
NSMutableDictionary *videoDic = [NSMutableDictionary dictionary];
[imageList enumerateObjectsUsingBlock:^(NSDictionary* obj1, NSUInteger idx1, BOOL *stop1) {
imageObjectBO *imgBO = setJsonDicToDataModel(obj1, [imageObjectBO class]);
if ([imgBO.tags isEqualToString:@"www_video"] || [imgBO.tags isEqualToString:@"www_big"]) {
[videoDic setValue:imgBO forKey:@"image"];
NSString *type = @"";
if (isTop) {
type = @"topvideo";
}else type = @"video";
[videoDic setValue:type forKey:@"type"];
*stop1 = YES;
}
}];
[videoList enumerateObjectsUsingBlock:^(id obj2, NSUInteger idx2, BOOL *stop2) {
videoObjectBO *video = setJsonDicToDataModel(obj2, [videoObjectBO class]);
CGFloat videoHeight = [videoSizeHight floatValue]*rect_screen.size.width/320;
if (isPad) {
videoHeight = [videoSizeHight floatValue]+[videoPadding floatValue];
}
NSAttributedString *attriString = getLineSpaceAttributedString(video.name, [iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
videoHeight = videoHeight + [self returnContentExtendHeight:attriString];
[videoDic setValue:video forKey:@"video"];
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
}else{
if (![video.isTap isEqualToString:@"1"]) {
videoHeight = 130 + [self returnContentExtendHeight:attriString];
}
}
[heightArray addObject:[NSString stringWithFormat:@"%f",videoHeight]];
}];
[contentArray addObject:videoDic];
}
NSArray *textAndContentList = liveCont.content; //文章详情
NSMutableArray *analysisedContentList = analysisContent(textAndContentList);
[analysisedContentList enumerateObjectsUsingBlock:^(id obj3, NSUInteger idx3, BOOL *stop3) {
if ([obj3 isKindOfClass:[imageObjectBO class]]) {
imageObjectBO *imageBO = obj3;
if ([imageBO.url isMatchedByRegex:@"224"]) {
imageBO.url = [imageBO.url stringByReplacingOccurrencesOfString:@"224" withString:@"247"];
}
CGFloat cellHeight = 0;
if ([imageBO.width floatValue] > contentWidth) {
cellHeight = [imageBO.height floatValue]*contentWidth/[imageBO.width floatValue];
}else cellHeight = [imageBO.height floatValue]*[cellHeightScale floatValue];
NSAttributedString *attriString = getLineSpaceAttributedString(imageBO.desc,
[iphoneLineSpaceAndParaSpace returnLevel3LineSpace_specialTopic],
appFont(TEXT_FOUR_LEVELSIZE, NO));
CGFloat imageExHeight = [self returnContentExtendHeight:attriString];
cellHeight = cellHeight+imageExHeight;
int readmode = [[TPUserDefault instance].readModeStr intValue];
if (readmode == intelligentMode) {
if ([Remote IsEnableWIFI]) {
readmode = imageMode;
}else {
readmode = textMode;
}
}
if (readmode == imageMode) {
}else{
cellHeight = 120+imageExHeight+10;
}
[heightArray addObject:[NSString stringWithFormat:@"%f",cellHeight]];
NSString *type = @"";
if (isTop) {
type = @"topimage";
}else type = @"image";
NSDictionary *imageDic = @{@"type":type,@"imageBO":imageBO,@"imageList":liveCont.textImages};
[contentArray addObject:imageDic];
}else {
NSString *str = obj3;
UIFont *font = appFont([TPUserDefault instance].contFontSize, NO);
if(isPad) {
font = appFont([TPUserDefault instance].contFontSize*3/4, NO);
}
NSArray *colorList = [str componentsMatchedByRegex:@"\\<[C]\\:[0-9A-Za-z]{6}>"];
__block NSString *oriStr = str;
[colorList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString* hexStr = [obj stringByMatching:@"[0-9A-Za-z]{6}"];
NSString *replacedStr = [NSString stringWithFormat:@"<color value=\"#%@\">",hexStr];
oriStr = [oriStr stringByReplacingOccurrencesOfRegex:obj withString:replacedStr];
}];
str = oriStr;
str = [str stringByReplacingOccurrencesOfString:@"<N>" withString:@"</>"];
// if (![str isMatchedByRegex:@"/font"]) {//修复bug:4487
// str = [str stringByAppendingString:@"</font>"];
// }
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = [iphoneLineSpaceAndParaSpace liveAndContentLineSpace];// 字体的行间距
paragraphStyle.alignment = NSTextAlignmentJustified;
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
// appFont([TPUserDefault instance].contFontSize, NO), NSFontAttributeName,
paragraphStyle,NSParagraphStyleAttributeName,
@0.0f,NSBaselineOffsetAttributeName,
// [UIColor colorWithHexString:TextBlack],NSForegroundColorAttributeName,
nil];
NSAttributedString *tempStr = attributedStringWithHtml(str);
NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithAttributedString:tempStr];
NSRange range = NSMakeRange(0, tempStr.length);
[attributeStr addAttributes:attributes range:range];
CGFloat strHeight = heightForAttributeStringWithLabel(attributeStr, contentWidth, font);
CGFloat cellHeight = strHeight+[iphoneLineSpaceAndParaSpace liveColumSpace];
[heightArray addObject:[NSString stringWithFormat:@"%f",cellHeight]];
NSString *type = @"";
if (isTop) {
type = @"topcontentText";
}else type = @"contentText";
NSDictionary *dic = @{@"type":type,@"text":attributeStr};
[contentArray addObject:dic];
}
}];
NSMutableDictionary *shareDic = [NSMutableDictionary dictionary];
NSString *type = @"";
if (isTop) {
type = @"topshare";
}else type = @"share";
[shareDic setValue:type forKey:@"type"];
[shareDic setValue:liveCont.name forKey:@"title"];
if (liveCont.strongRelateCont) {
listContObjectVO *listBO = setJsonDicToDataModel(liveCont.strongRelateCont, [listContObjectVO class]);
[shareDic setValue:listBO forKey:@"strongRelate"];
}
[contentArray addObject:shareDic];
[heightArray addObject:[NSString stringWithFormat:@"%f",55.f]];
}
- (CGFloat)returnContentExtendHeight:(NSAttributedString*)str {
BOOL isHaveDesc = NO;
if (str.length > 0) {
isHaveDesc = YES;
}
if (isHaveDesc) {
// descHeight = returnTextHeightWithRTLabel(str, imageDescWidth, appFont(TEXT_FOUR_LEVELSIZE, NO), [imageLineSpace floatValue]);
CGFloat descHeight = heightForAttributeStringWithLabel(str,
imageDescWidth,
appFont(TEXT_FOUR_LEVELSIZE, NO));
return descHeight + [iphoneLineSpaceAndParaSpace returnImageParaSpace]+5;
}else {
return [iphoneLineSpaceAndParaSpace returnImageLineSpace];
}
}
#pragma mark - remote delegate
- (void)startWaitCursor:(int)actionTag {
}
- (void)stopWaitCursor:(int)actionTag {
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
if (actionTag == getLiveInfoTag) {
self.livePageBO = setJsonDicToDataModel(responsData, [liveDetailPageVO class]);
self.liveInfoBO = setJsonDicToDataModel(self.livePageBO.liveInfo, [liveInfoBO class]);
}else if (actionTag == getCommentInfoTag) {
NSMutableArray* commentList = [NSMutableArray array];
NSMutableArray *hotList = [NSMutableArray array];
NSArray *list = responsData[@"commentList"];
NSArray *hotDicList = responsData[@"hotList"];
[list enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO);
[commentList addObject:commentBO];
}];
[hotDicList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO);
[hotList addObject:commentBO];
}];
NSMutableArray *commentDataList = [NSMutableArray array];
if (hotList.count > 0) {
[commentDataList addObject:hotList];
}
[commentDataList addObject:commentList];
if ([self.delegate respondsToSelector:@selector(returnCommentList:nodeId:nextUrl:commentTotalRecord:)]) {
NSMutableArray *array = [NSMutableArray array];
if (isPad) {
array = [NSMutableArray arrayWithArray:commentList];
}else {
array = [NSMutableArray arrayWithArray:commentDataList];
}
[self.delegate returnCommentList:array
nodeId:self.nodeId
nextUrl:responsData[@"nextUrl"]
commentTotalRecord:[responsData[@"recordTotal"] integerValue]];
}
}else if (actionTag == getAskInfoTag) {
NSMutableDictionary *qaDataDic = [NSMutableDictionary dictionary];
NSArray *hotQaList = responsData[@"hotQaList"];
NSMutableArray *hotQaArray = [NSMutableArray array];
[hotQaList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO);
[hotQaArray addObject:commentBO];
}];
[qaDataDic setValue:hotQaArray forKey:@"hotQaList"];
NSArray *qaTempList = responsData[@"qaList"];
NSMutableArray *qaArray = [NSMutableArray array];
[qaTempList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO);
[qaArray addObject:commentBO];
}];
[qaDataDic setValue:qaArray forKey:@"qaList"];
if ([self.delegate respondsToSelector:@selector(returnHotAskDic:nodeId:nextUrl:askTotalRecord:)]) {
[self.delegate returnHotAskDic:qaDataDic
nodeId:self.nodeId
nextUrl:responsData[@"nextUrl"]
askTotalRecord:[responsData[@"qaNum"] integerValue]];
}
if ([self.delegate respondsToSelector:@selector(stopHudAnimation)]) {
[self.delegate stopHudAnimation];
}
}else if (actionTag == loadMoreTag) {
if ([self.delegate respondsToSelector:@selector(returnMoreInfoData:)]) {
[self.delegate returnMoreInfoData:responsData];
}
}
}
- (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code {
if ([self.delegate respondsToSelector:@selector(stopHudAnimation)]) {
[self.delegate stopHudAnimation];
}
if ([code intValue] == 5) {
if ([self.delegate respondsToSelector:@selector(contentHaveOffline)]) {
[self.delegate contentHaveOffline];
}
}else {
BOOL isTimeOut = NO;
if ([message isEqualToString:@"请求超时,请稍后重试!"]) {
isTimeOut = YES;
}else {
if ([message isEqualToString:@"网络连接中断,请检查网络设置!"]) {
isTimeOut = YES;
}
ShowTextMessage(message);
}
if ([self.delegate respondsToSelector:@selector(remoteFail:)]) {
[self.delegate remoteFail:isTimeOut];
}
}
}
#pragma mark - video delegate
//- (void)playFinish:(NSNotification*)notification {
// [self stopAndRemoveVideo];
//}
- (void)captureVideoPhoto {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(rect_screen.size.width, rect_screen.size.height), YES, 0); //设置截屏大小
[[self.moviePlayerController.view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = viewImage.CGImage;
CGRect rect = CGRectMake(0, 0, rect_screen.size.width, rect_screen.size.height);//这里可以设置想要截图的区域
CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];
UIImageWriteToSavedPhotosAlbum(sendImage, nil, nil, nil);//保存图片到照片库
}
- (void)moviePlayerWillMoveFromWindow {
}
- (void)movieTimedOut {
// [self stopAndRemoveVideo];
}
- (void)enterFullScreen:(BOOL)isEnter {
[self closeHandler];
}
- (void)closeHandler {
[self.delegate turnToPortrait];
[self stopAndRemoveVideo];
}
- (void)turnToright {
[self.delegate turnToright];
}
- (void)stopAndRemoveVideo {
[self.moviePlayerController selfDealloc];
[self.moviePlayerController.view removeFromSuperview];
self.moviePlayerController = nil;
self.moviePlayerController.view = nil;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
|