Skip to content

fix bug #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MessageDisplayKit/Classes/Common/XHAudioPlayerHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ - (void)stopAudio {
if (_player && _player.isPlaying) {
[_player stop];
}
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
if ([self.delegate respondsToSelector:@selector(didAudioPlayerStopPlay:)]) {
[self.delegate didAudioPlayerStopPlay:_player];
Expand Down Expand Up @@ -180,11 +181,13 @@ - (void)sensorStateChange:(NSNotificationCenter *)notification {
//黑屏
DLog(@"Device is close to user");
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];

} else {
//没黑屏幕
DLog(@"Device is not close to user");
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
if (!_player || !_player.isPlaying) {
//没有播放了,也没有在黑屏状态下,就可以把距离传感器关了
[[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
Expand Down
3 changes: 2 additions & 1 deletion MessageDisplayKit/Classes/Common/XHVoiceRecordHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ - (void)cancelRecording {

- (void)stopRecord {
[self cancelRecording];
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[self resetTimer];
}

Expand All @@ -107,7 +108,7 @@ - (void)prepareRecordingWithPath:(NSString *)path prepareRecorderCompletion:(XHP
}

error = nil;
[audioSession setActive:YES error:&error];
[audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];
if(error) {
DLog(@"audioSession: %@ %ld %@", [error domain], (long)[error code], [[error userInfo] description]);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "XHMessageBubbleFactory.h"

#define kXHBubblePhotoMargin 8.0f // 上下左右的边距

#define kXHMaxBubblePhotoWidth 280.0f//最大图片宽度
@interface XHBubblePhotoImageView : UIView

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#import "XHConfigurationHelper.h"
#import "XHMacro.h"
#import "XHMessageBubbleView.h"

@interface XHBubblePhotoImageView ()

Expand Down Expand Up @@ -46,8 +47,10 @@ - (void)setMessagePhoto:(UIImage *)messagePhoto {

- (void)configureMessagePhoto:(UIImage *)messagePhoto thumbnailUrl:(NSString *)thumbnailUrl originPhotoUrl:(NSString *)originPhotoUrl onBubbleMessageType:(XHBubbleMessageType)bubbleMessageType {
self.bubbleMessageType = bubbleMessageType;
self.messagePhoto = messagePhoto;

if (messagePhoto) {
[self updateBubbleViewWithImage:messagePhoto];
}
if (thumbnailUrl) {
WEAKSELF
[self addSubview:self.activityIndicatorView];
Expand All @@ -68,25 +71,62 @@ - (void)configureMessagePhoto:(UIImage *)messagePhoto thumbnailUrl:(NSString *)t
weakSelf.semaphore = nil;
}
}

// if image not nil
if (image) {
// scale image
image = [image thumbnailImage:CGRectGetWidth(weakSelf.bounds) * 2 transparentBorder:0 cornerRadius:0 interpolationQuality:1.0];
dispatch_async(dispatch_get_main_queue(), ^{
// if image not nil
if (image) {
// show image
weakSelf.messagePhoto = image;
[weakSelf.activityIndicatorView stopAnimating];
}
});
[weakSelf updateBubbleViewWithImage:image];
}

}
}];
}
}

/**
* 根据图片更新BubbleView(主要设置图片大小尺寸)
*/
- (void)updateBubbleViewWithImage:(UIImage *)image {

// scale image
CGSize size = [self needSizeForImage:image];
image = [image resizedImage:size interpolationQuality:1.0];
//图片太宽进行剪切,以免图片变形(截取中间的进行显示)
if (size.width > kXHMaxBubblePhotoWidth) {
image = [image croppedImage:CGRectMake((size.width - kXHMaxBubblePhotoWidth)/2, 0, kXHMaxBubblePhotoWidth, size.height)];
size = CGSizeMake(kXHMaxBubblePhotoWidth, size.height);
}

WEAKSELF
dispatch_async(dispatch_get_main_queue(), ^{
// if image not nil
if (image) {
UIView *view = weakSelf.superview;
if ([view isKindOfClass:[XHMessageBubbleView class]]) {
XHMessageBubbleView * bubble = (XHMessageBubbleView *)view;

bubble.sizeForBubblePhotoImageView = size;
[bubble layoutSubviews];
}
// show image
weakSelf.messagePhoto = image;
[weakSelf.activityIndicatorView stopAnimating];
}
});
}

/**
* 计算图片需要显示的大小,高度140计
*/
- (CGSize)needSizeForImage:(UIImage *) photo {
// 这里需要缩放后的size
CGSize photoSize ;

CGFloat photoWidth = photo.size.width;
CGFloat photoHeight = photo.size.height;
CGFloat realWidth = photoWidth * 140 / photoHeight;
photoSize = CGSizeMake(realWidth, 140);
return photoSize;
}

- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
if (self.semaphore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
*/
@property (nonatomic, strong) UIFont *font UI_APPEARANCE_SELECTOR;

/**
* 图片实际显示尺寸
*/
@property (nonatomic,assign) CGSize sizeForBubblePhotoImageView;

/**
* 初始化消息内容显示控件的方法
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ - (void)layoutSubviews {
case XHBubbleMessageMediaTypeVideo:
case XHBubbleMessageMediaTypeLocalPosition: {
CGSize needPhotoSize = [XHMessageBubbleView neededSizeForPhoto:self.message.photo];
if (!CGSizeEqualToSize(_sizeForBubblePhotoImageView,CGSizeZero)) {
needPhotoSize = _sizeForBubblePhotoImageView;
}

CGFloat paddingX = 0.0f;
if (self.message.bubbleMessageType == XHBubbleMessageTypeSending) {
paddingX = CGRectGetWidth(self.bounds) - needPhotoSize.width;
Expand Down