forked from mirrors/linphone-iphone
enable share and play videos not from photo library
This commit is contained in:
parent
78c67fb4ec
commit
cbfdb96de7
4 changed files with 43 additions and 20 deletions
|
|
@ -260,18 +260,15 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
[_messageField setText:dict[@"message"]];
|
||||
NSString *key = [[fileName componentsSeparatedByString:@"."] firstObject];
|
||||
NSMutableDictionary <NSString *, PHAsset *> * assetDict = [LinphoneUtils photoAssetsDictionary];
|
||||
|
||||
if ([fileName hasSuffix:@"JPG"] || [fileName hasSuffix:@"PNG"] || [fileName hasSuffix:@"jpg"] || [fileName hasSuffix:@"png"]) {
|
||||
PHAsset *phasset = [assetDict objectForKey:key];
|
||||
if (!phasset) {
|
||||
// for the images not really in the photo album
|
||||
[self confirmShare:dict[@"nsData"] url:nil fileName:fileName assetId:nil];
|
||||
} else {
|
||||
UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]];
|
||||
[self chooseImageQuality:image assetId:[phasset localIdentifier]];
|
||||
}
|
||||
PHAsset *phasset = [assetDict objectForKey:key];
|
||||
if (!phasset) {
|
||||
// for the images or videos not really in the photo album
|
||||
[self confirmShare:dict[@"nsData"] url:nil fileName:fileName assetId:nil];
|
||||
} else if ([fileName hasSuffix:@"JPG"] || [fileName hasSuffix:@"PNG"] || [fileName hasSuffix:@"jpg"] || [fileName hasSuffix:@"png"]) {
|
||||
UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]];
|
||||
[self chooseImageQuality:image assetId:[phasset localIdentifier]];
|
||||
} else if ([fileName hasSuffix:@"MOV"] || [fileName hasSuffix:@"mov"]) {
|
||||
[self confirmShare:dict[@"nsData"] url:nil fileName:nil assetId:[[assetDict objectForKey:key] localIdentifier]];
|
||||
[self confirmShare:dict[@"nsData"] url:nil fileName:nil assetId:[phasset localIdentifier]];
|
||||
} else {
|
||||
LOGE(@"Unable to parse file %@",fileName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,6 +198,10 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
} else if ([localFile hasSuffix:@"MOV"] || [localFile hasSuffix:@"mov"]) {
|
||||
UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
} else {
|
||||
NSString *text = [NSString stringWithFormat:@"📎 %@",localFile];
|
||||
_fileName.text = text;
|
||||
|
|
@ -215,7 +219,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
} else {
|
||||
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES;
|
||||
fullScreenImage = YES;
|
||||
_playButton.hidden = localVideo ? NO : YES;
|
||||
_playButton.hidden = localVideo ? NO : ([localFile hasSuffix:@"MOV"] || [localFile hasSuffix:@"mov"]) ? NO : YES;
|
||||
_fileName.hidden = _fileView.hidden = _fileButton.hidden = localFile ? NO : YES;
|
||||
// Should fix cell not resizing after doanloading image.
|
||||
[self layoutSubviews];
|
||||
|
|
@ -251,6 +255,13 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
});
|
||||
}
|
||||
|
||||
- (void)playVideoByPlayer:(AVPlayer *)player {
|
||||
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
|
||||
[PhoneMainView.instance presentViewController:controller animated:YES completion:nil];
|
||||
controller.player = player;
|
||||
[player play];
|
||||
}
|
||||
|
||||
- (IBAction)onDownloadClick:(id)event {
|
||||
[_ftd cancel];
|
||||
_ftd = [[FileTransferDelegate alloc] init];
|
||||
|
|
@ -264,17 +275,19 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
|
||||
- (IBAction)onPlayClick:(id)sender {
|
||||
PHAsset *asset = [_messageImageView asset];
|
||||
if (!asset) {
|
||||
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
|
||||
AVPlayer *player = [AVPlayer playerWithURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
[self playVideoByPlayer:player];
|
||||
return;
|
||||
}
|
||||
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
|
||||
// options.synchronous = TRUE;
|
||||
[[PHImageManager defaultManager] requestPlayerItemForVideo:asset options:options resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
|
||||
if(playerItem) {
|
||||
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
|
||||
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
|
||||
[PhoneMainView.instance presentViewController:controller animated:YES completion:nil];
|
||||
controller.player = player;
|
||||
[player play];
|
||||
}
|
||||
else {
|
||||
[self playVideoByPlayer:player];
|
||||
} else {
|
||||
[self fileErrorBlock];
|
||||
}
|
||||
}];
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
+ (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width;
|
||||
+ (CGSize)ViewHeightForMessageText:(LinphoneChatMessage *)chat withWidth:(int)width textForImdn:(NSString *)imdnText;
|
||||
+ (CGSize)getMediaMessageSizefromOriginalSize:(CGSize)originalSize withWidth:(int)width;
|
||||
+ (UIImage *)getImageFromVideoUrl:(NSURL *)url;
|
||||
|
||||
- (void)setEvent:(LinphoneEventLog *)event;
|
||||
- (void)setChatMessage:(LinphoneChatMessage *)message;
|
||||
|
|
|
|||
|
|
@ -465,11 +465,16 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
}
|
||||
|
||||
if(localFile) {
|
||||
UIImage *image = nil;
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"] || [localFile hasSuffix:@"jpg"] || [localFile hasSuffix:@"png"]) {
|
||||
NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
image = [[UIImage alloc] initWithData:data];
|
||||
} else if ([localFile hasSuffix:@"MOV"] || [localFile hasSuffix:@"mov"]) {
|
||||
image = [self getImageFromVideoUrl:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
|
||||
}
|
||||
|
||||
if (image) {
|
||||
size = [self getMediaMessageSizefromOriginalSize:image.size withWidth:width];
|
||||
|
||||
// add size for message text
|
||||
size.height += textSize.height;
|
||||
size.width = MAX(textSize.width, size.width);
|
||||
|
|
@ -528,6 +533,13 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
return messageSize;
|
||||
}
|
||||
|
||||
+ (UIImage *)getImageFromVideoUrl:(NSURL *)url {
|
||||
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:url options:nil];
|
||||
AVAssetImageGenerator* generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
|
||||
generator.appliesPreferredTrackTransform = YES;
|
||||
return [UIImage imageWithCGImage:[generator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
if (_message != nil) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue