You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
5.5 KiB
130 lines
5.5 KiB
// |
|
// XHDisplayMediaViewController.m |
|
// MessageDisplayExample |
|
// |
|
// Created by HUAJIE-1 on 14-5-6. |
|
// Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved. |
|
// |
|
|
|
#import "XHDisplayMediaViewController.h" |
|
#import <MediaPlayer/MediaPlayer.h> |
|
|
|
#import "UIView+XHRemoteImage.h" |
|
#import "XHConfigurationHelper.h" |
|
|
|
#import "CJFileUtility.h" |
|
|
|
@interface XHDisplayMediaViewController () |
|
|
|
@property (nonatomic, strong) MPMoviePlayerController *moviePlayerController; |
|
|
|
@property (nonatomic, weak) UIImageView *photoImageView; |
|
|
|
@end |
|
|
|
@implementation XHDisplayMediaViewController |
|
|
|
- (MPMoviePlayerController *)moviePlayerController { |
|
if (!_moviePlayerController) { |
|
_moviePlayerController = [[MPMoviePlayerController alloc] init]; |
|
_moviePlayerController.repeatMode = MPMovieRepeatModeOne; |
|
_moviePlayerController.scalingMode = MPMovieScalingModeAspectFill; |
|
_moviePlayerController.view.frame = self.view.frame; |
|
[self.view addSubview:_moviePlayerController.view]; |
|
} |
|
return _moviePlayerController; |
|
} |
|
|
|
- (UIImageView *)photoImageView { |
|
if (!_photoImageView) { |
|
UIImageView *photoImageView = [[UIImageView alloc] initWithFrame:(CGRect){0,0,SWIDTH,SHEIGHT - 64}]; |
|
photoImageView.contentMode = UIViewContentModeScaleAspectFit; |
|
// photoImageView.clipsToBounds = YES; |
|
[self.view addSubview:photoImageView]; |
|
_photoImageView = photoImageView; |
|
} |
|
return _photoImageView; |
|
} |
|
|
|
- (void)setMessage:(XHMessage *)message { |
|
_message = message; |
|
if ([message messageMediaType] == XHBubbleMessageMediaTypeVideo) { |
|
self.title = NSLocalizedStringFromTable(@"Video", @"MessageDisplayKitString", @"详细视频"); |
|
self.moviePlayerController.contentURL = [NSURL fileURLWithPath:[message videoPath]]; |
|
[self.moviePlayerController play]; |
|
} else if ([message messageMediaType] ==XHBubbleMessageMediaTypePhoto) { |
|
self.title = NSLocalizedStringFromTable(@"Photo", @"MessageDisplayKitString", @"详细照片"); |
|
self.photoImageView.image = message.photo; |
|
if (message.content) { |
|
if (!message.photo) { |
|
NSString *path = [CJFileUtility documentsPathSubDir:@"msg_image" andFile:[_message id]]; |
|
UIImage *image = [UIImage imageWithContentsOfFile:path]; |
|
if (!image) { |
|
NSString *placeholderImageName = [[XHConfigurationHelper appearance].messageInputViewStyle objectForKey:kXHMessageTablePlaceholderImageNameKey]; |
|
|
|
if (!placeholderImageName) { |
|
placeholderImageName = @"placeholderImage"; |
|
} |
|
[self.photoImageView setImageWithURL:[NSURL URLWithString:message.content] |
|
placeholer:[UIImage imageNamed:placeholderImageName] |
|
showActivityIndicatorView:NO |
|
completionBlock:^(UIImage *image, NSURL *url, NSError *error) { |
|
NSString *path = [CJFileUtility documentsPathSubDir:@"msg_image" |
|
andFile:_message.id]; |
|
[CJFileUtility writeToFile:path data:UIImageJPEGRepresentation(image ,1)]; |
|
}]; |
|
}else{ |
|
[self.photoImageView setImageWithURL:[NSURL URLWithString:message.content] |
|
placeholer:image |
|
showActivityIndicatorView:NO |
|
completionBlock:^(UIImage *image, NSURL *url, NSError *error) { |
|
NSString *path = [CJFileUtility documentsPathSubDir:@"msg_image" |
|
andFile:_message.id]; |
|
[CJFileUtility writeToFile:path data:UIImageJPEGRepresentation(image ,1)]; |
|
}]; |
|
} |
|
|
|
|
|
}else{ |
|
[self.photoImageView setImageWithURL:[NSURL URLWithString:message.content] |
|
placeholer:message.photo |
|
showActivityIndicatorView:NO |
|
completionBlock:^(UIImage *image, NSURL *url, NSError *error) { |
|
NSString *path = [CJFileUtility documentsPathSubDir:@"msg_image" |
|
andFile:_message.id]; |
|
[CJFileUtility writeToFile:path data:UIImageJPEGRepresentation(image ,1)]; |
|
}]; |
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
#pragma mark - Life cycle |
|
|
|
- (void)viewWillDisappear:(BOOL)animated { |
|
[super viewWillDisappear:animated]; |
|
if ([self.message messageMediaType] == XHBubbleMessageMediaTypeVideo) { |
|
[self.moviePlayerController stop]; |
|
} |
|
} |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.view.backgroundColor = [UIColor blackColor]; |
|
} |
|
|
|
- (void)didReceiveMemoryWarning { |
|
[super didReceiveMemoryWarning]; |
|
// Dispose of any resources that can be recreated. |
|
} |
|
|
|
- (void)dealloc { |
|
[_moviePlayerController stop]; |
|
_moviePlayerController = nil; |
|
|
|
_photoImageView = nil; |
|
} |
|
|
|
@end
|
|
|