Skip to content

Commit

Permalink
memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
annidyfeng committed Sep 20, 2018
1 parent 448f699 commit 1a0eaa7
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 300 deletions.
4 changes: 4 additions & 0 deletions Example/Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>访问相机</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>访问相册</string>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
Expand Down
51 changes: 49 additions & 2 deletions Example/Example/MoviePlayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ - (void)viewWillAppear:(BOOL)animated {
_guideView.missHandler = ^{
wplayer.isLockScreen = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[wplayer showControlView:NO];
[self showControlView:NO];

[df setBool:YES forKey:@"isShowGuide"];
[df synchronize];
Expand Down Expand Up @@ -331,7 +331,7 @@ - (void)viewDidLoad {
if (allList.count > 0) {
[self.playerView playWithModel:[_liveDataSourceArray[0] getPlayerModel]];
if (self.guideView) {
[self.playerView showControlView:YES];
[self showControlView:YES];
}
}

Expand Down Expand Up @@ -377,6 +377,7 @@ - (SuperPlayerView *)playerView {
_playerView.fatherView = _playerFatherView;
// 设置代理
_playerView.delegate = self;
[self setupDanmakuData];
}
return _playerView;
}
Expand Down Expand Up @@ -582,6 +583,52 @@ - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)
return NO;
}

#define kRandomColor [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]
#define font [UIFont systemFontOfSize:15]

- (void)setupDanmakuData
{
NSString *danmakufile = [[NSBundle mainBundle] pathForResource:@"danmakufile" ofType:nil];
NSArray *danmakusDicts = [NSArray arrayWithContentsOfFile:danmakufile];

NSMutableArray* danmakus = [NSMutableArray array];
for (NSDictionary* dict in danmakusDicts) {
CFDanmaku* danmaku = [[CFDanmaku alloc] init];
NSMutableAttributedString *contentStr = [[NSMutableAttributedString alloc] initWithString:dict[@"m"] attributes:@{NSFontAttributeName : font, NSForegroundColorAttributeName : kRandomColor}];

NSString* emotionName = [NSString stringWithFormat:@"smile_%u", arc4random_uniform(90)];
UIImage* emotion = [UIImage imageNamed:emotionName];
NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
attachment.image = emotion;
attachment.bounds = CGRectMake(0, -font.lineHeight*0.3, font.lineHeight*1.5, font.lineHeight*1.5);
NSAttributedString* emotionAttr = [NSAttributedString attributedStringWithAttachment:attachment];

[contentStr appendAttributedString:emotionAttr];
danmaku.contentStr = contentStr;

NSString* attributesStr = dict[@"p"];
NSArray* attarsArray = [attributesStr componentsSeparatedByString:@","];
danmaku.timePoint = [[attarsArray firstObject] doubleValue] / 1000;
danmaku.position = [attarsArray[1] integerValue];
// if (danmaku.position != 0) {

[danmakus addObject:danmaku];
// }
}

[self.playerView.danmakuView prepareDanmakus:danmakus];
}

- (void)showControlView:(BOOL)isShow {
if (isShow) {
[self.playerView.controlView playerShowControlView];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.playerView.controlView playerCancelAutoFadeOutControlView];
});
} else {
[self.playerView.controlView playerHideControlView];
}
}

#pragma mark - ScrollView Delegate

Expand Down
4 changes: 2 additions & 2 deletions SuperPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |spec|
spec.name = 'SuperPlayer'
spec.version = '1.0.3'
spec.version = '1.0.4'
spec.license = { :type => 'MIT' }
spec.homepage = 'https://cloud.tencent.com/product/mlvb'
spec.authors = { 'annidyfeng' => '[email protected]' }
spec.summary = 'Tencent Cloud Player'
spec.source = { :git => 'https://github.com/tencentyun/SuperPlayer.git', :tag => 'v1.0.3' }
spec.source = { :git => 'https://github.com/tencentyun/SuperPlayer.git', :tag => 'v1.0.4' }

spec.ios.deployment_target = '8.0'
spec.requires_arc = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#import <UIKit/UIKit.h>

@interface UINavigationController (SuperPlayerRotation)<UIGestureRecognizerDelegate>

@end
34 changes: 34 additions & 0 deletions SuperPlayer/Category/UINavigationController+SuperPlayerRotation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#import "UINavigationController+SuperPlayerRotation.h"
#import <objc/runtime.h>

@implementation UINavigationController (SuperPlayerRotation)

/**
* 如果window的根视图是UINavigationController,则会先调用这个Category,然后调用UIViewController+ZFPlayerRotation
* 只需要在支持除竖屏以外方向的页面重新下边三个方法
*/

// 是否支持自动转屏
- (BOOL)shouldAutorotate {
return [self.topViewController shouldAutorotate];
}

// 支持哪些屏幕方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}

// 默认的屏幕方向(当前ViewController必须是通过模态出来的UIViewController(模态带导航的无效)方式展现出来的,才会调用这个方法)
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [self.topViewController preferredInterfaceOrientationForPresentation];
}

- (UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}

- (UIViewController *)childViewControllerForStatusBarHidden {
return self.topViewController;
}

@end
28 changes: 0 additions & 28 deletions SuperPlayer/Category/UINavigationController+ZFPlayerRotation.h

This file was deleted.

57 changes: 0 additions & 57 deletions SuperPlayer/Category/UINavigationController+ZFPlayerRotation.m

This file was deleted.

5 changes: 5 additions & 0 deletions SuperPlayer/Category/UIViewController+SuperPlayerRotation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>

@interface UIViewController (SuperPlayerRotation)

@end
32 changes: 32 additions & 0 deletions SuperPlayer/Category/UIViewController+SuperPlayerRotation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#import "UIViewController+SuperPlayerRotation.h"

@implementation UIViewController (SuperPlayerRotation)

/**
* 默认所有都不支持转屏,如需个别页面支持除竖屏外的其他方向,请在viewController重新下边这三个方法
*/

// 是否支持自动转屏
- (BOOL)shouldAutorotate {
return NO;
}

// 支持哪些屏幕方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

// 默认的屏幕方向(当前ViewController必须是通过模态出来的UIViewController(模态带导航的无效)方式展现出来的,才会调用这个方法)
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault; // your own style
}

- (BOOL)prefersStatusBarHidden {
return NO; // your own visibility code
}

@end
28 changes: 0 additions & 28 deletions SuperPlayer/Category/UIViewController+ZFPlayerRotation.h

This file was deleted.

55 changes: 0 additions & 55 deletions SuperPlayer/Category/UIViewController+ZFPlayerRotation.m

This file was deleted.

5 changes: 4 additions & 1 deletion SuperPlayer/SuperPlayerGlobleConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
@property (nonatomic) CGRect floatViewRect;
/** 是否开启硬件加速 */
@property (nonatomic) BOOL enableHWAcceleration;
/** 默认播放填充模式 */
/**
* 默认播放填充模式
* 可选值 RENDER_MODE_FILL_EDGE, RENDER_MODE_FILL_SCREEN
*/
@property (nonatomic) NSInteger renderMode;
/** 播放器最大缓存个数 */
@property (nonatomic) NSInteger maxCacheItem;
Expand Down
12 changes: 8 additions & 4 deletions SuperPlayer/SuperPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#import "TXLivePlayer.h"
#import "TXLiveBase.h"
#import "TXImageSprite.h"
#import "CFDanmakuView.h"

@class SuperPlayerControlView;

@protocol SuperPlayerDelegate <NSObject>
@optional
Expand Down Expand Up @@ -41,6 +44,11 @@ typedef NS_ENUM(NSInteger, SuperPlayerState) {
@property (nonatomic, assign) BOOL isLockScreen;
/** 是否是直播流 */
@property (readonly) BOOL isLive;
/// 弹幕视图
@property CFDanmakuView *danmakuView;
/// 超级播放器控制层
@property SuperPlayerControlView *controlView;

/**
* 播放model
*/
Expand All @@ -61,8 +69,4 @@ typedef NS_ENUM(NSInteger, SuperPlayerState) {
*/
- (void)pause;

/**
* 是否显示控制层
*/
- (void)showControlView:(BOOL)isShow;
@end
Loading

0 comments on commit 1a0eaa7

Please sign in to comment.