Skip to content

Commit

Permalink
Add Mute. v2微调.
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Feb 6, 2018
2 parents a439ddb + 228d2e8 commit e36a145
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SJVideoPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SJVideoPlayer'
s.version = '2.0.0'
s.version = '2.0.0.1'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJVideoPlayer'
Expand Down
Binary file modified SJVideoPlayer/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions SJVideoPlayer/Header/SJVideoPlayerControlDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
- (void)videoPlayer:(SJVideoPlayer *)videoPlayer willRotateView:(BOOL)isFull; // 播放器将要旋转屏幕, `isFull`如果为`YES`, 则全屏.

#pragma mark - 音量 / 亮度 / 播放速度
- (void)videoPlayer:(SJVideoPlayer *)videoPlayer muteChanged:(BOOL)mute; // 静音开关变更

- (void)videoPlayer:(SJVideoPlayer *)videoPlayer volumeChanged:(float)volume; // 声音被改变.

- (void)videoPlayer:(SJVideoPlayer *)videoPlayer brightnessChanged:(float)brightness; // 亮度被改变.
Expand Down
2 changes: 2 additions & 0 deletions SJVideoPlayer/SJVideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface SJVideoPlayer (Control)

@property (nonatomic, readwrite) BOOL mute; // default is no. 静音.

/*!
* The user clicked paused.
*
Expand Down
22 changes: 21 additions & 1 deletion SJVideoPlayer/SJVideoPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ - (void)dealloc {
- (void)setAsset:(SJVideoPlayerAssetCarrier *)asset {
_asset = asset;
if ( !asset ) return;
if ( self.mute ) self.mute = YES; // update
self.presentView.player = self.asset.player;
[self _itemPrepareToPlay];

Expand Down Expand Up @@ -323,7 +324,13 @@ - (void)_itemReadyToPlay {
}

[self play];
[self.displayRecorder needDisplay];

__weak typeof(self) _self = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
__strong typeof(_self) self = _self;
if ( !self ) return;
[self.displayRecorder needDisplay];
});
}

- (void)_itemPlayDidToEnd {
Expand Down Expand Up @@ -847,6 +854,19 @@ - (void)seekToTime:(CMTime)time completionHandler:(void (^ __nullable)(BOOL fini

@implementation SJVideoPlayer (Control)

- (void)setMute:(BOOL)mute {
if ( mute == self.mute ) return;
objc_setAssociatedObject(self, @selector(mute), @(mute), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
self.asset.player.volume = !mute;
if ( [self.controlViewDelegate respondsToSelector:@selector(videoPlayer:muteChanged:)] ) {
[self.controlViewDelegate videoPlayer:self muteChanged:mute];
}
}

- (BOOL)mute {
return [objc_getAssociatedObject(self, _cmd) boolValue];
}

- (BOOL)userPaused {
return self.userClickedPause;
}
Expand Down
2 changes: 2 additions & 0 deletions SJVideoPlayer/SJVideoPlayerDefaultControlView.m
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,9 @@ - (void)videoPlayer:(SJVideoPlayer *)videoPlayer presentationSize:(CGSize)size {
__strong typeof(_self) self = _self;
if ( !self ) return ;
if ( error ) {
#ifndef DEBUG
NSLog(@"Generate Preview Image Failed! error: %@", error);
#endif
}
else {
self.hasBeenGeneratedPreviewImages = YES;
Expand Down
Binary file modified SJVideoPlayerProject/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
<action selector="push:" destination="BYZ-38-t0r" eventType="touchUpInside" id="3t4-xO-YZt"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="TeN-Vk-3Jj">
<rect key="frame" x="329" y="625" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Test"/>
<connections>
<action selector="test:" destination="BYZ-38-t0r" eventType="touchUpInside" id="8gL-hF-Hrz"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,57 @@ - (void)_createNewPlayerWithView:(UIView *)view
}

@end

#if 0
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
static UIImage *frameImage(CGSize size, CGFloat radians) {
UIGraphicsBeginImageContextWithOptions(size, YES, 1); {
[[UIColor whiteColor] setFill];
UIRectFill(CGRectInfinite);
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(gc, size.width / 2, size.height / 2);
CGContextRotateCTM(gc, radians);
CGContextTranslateCTM(gc, size.width / 4, 0);
[[UIColor redColor] setFill];
CGFloat w = size.width / 10;
CGContextFillEllipseInRect(gc, CGRectMake(-w / 2, -w / 2, w, w));
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
static void makeAnimatedGif(void) {
static NSUInteger kFrameCount = 16;
NSDictionary *fileProperties = @{
(__bridge id)kCGImagePropertyGIFDictionary: @{
(__bridge id)kCGImagePropertyGIFLoopCount: @0, // 0 means loop forever
}
};

NSDictionary *frameProperties = @{
(__bridge id)kCGImagePropertyGIFDictionary: @{
(__bridge id)kCGImagePropertyGIFDelayTime: @0.02f, // a float (not double!) in seconds, rounded to centiseconds in the GIF data
}
};
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSURL *fileURL = [documentsDirectoryURL URLByAppendingPathComponent:@"animated.gif"];

CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, kUTTypeGIF, kFrameCount, NULL);
CGImageDestinationSetProperties(destination, (__bridge CFDictionaryRef)fileProperties);

for (NSUInteger i = 0; i < kFrameCount; i++) {
@autoreleasepool {
UIImage *image = frameImage(CGSizeMake(300, 300), M_PI * 2 * i / kFrameCount);
CGImageDestinationAddImage(destination, image.CGImage, (__bridge CFDictionaryRef)frameProperties);
}
}

if (!CGImageDestinationFinalize(destination)) {
NSLog(@"failed to finalize image destination");
}
CFRelease(destination);

NSLog(@"url=%@", fileURL);
}
#endif
2 changes: 2 additions & 0 deletions SJVideoPlayerProject/SJVideoPlayerProject/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ - (IBAction)pushNested:(id)sender {
- (IBAction)demo:(id)sender {
[self.navigationController pushViewController:[[SJVideoListViewController alloc] init] animated:YES];
}
- (IBAction)test:(id)sender {
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
Expand Down

0 comments on commit e36a145

Please sign in to comment.