Skip to content
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
2 changes: 1 addition & 1 deletion Sources/SCScrollableWaveformView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
#import "SCWaveformView.h"

@interface SCScrollableWaveformView : UIScrollView
@interface SCScrollableWaveformView : UIScrollView<UIScrollViewDelegate>

@property (readonly, nonatomic) SCWaveformView *waveformView;

Expand Down
24 changes: 24 additions & 0 deletions Sources/SCScrollableWaveformView.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ - (void)_commonInit {
[self addSubview:_waveformView];

[self addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:ScrollableWaveformContentOffsetContext];

self.delegate = self;
}

- (void)_setAutoNeedsDisplayedEnabled:(BOOL)enabled {
_waveformView.needsDisplayOnProgressTimeChange = enabled;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self _setAutoNeedsDisplayedEnabled:YES];
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
[self _setAutoNeedsDisplayedEnabled:YES];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self _setAutoNeedsDisplayedEnabled:NO];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
[self _setAutoNeedsDisplayedEnabled:YES];
}
}

- (void)dealloc {
Expand Down
20 changes: 9 additions & 11 deletions Sources/SCWaveformCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ - (BOOL)readTimeRange:(CMTimeRange)timeRange width:(CGFloat)width error:(NSError
}

if (shouldReadAsset) {
NSDictionary *outputSettingsDict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
nil];
NSDictionary *outputSettingsDict = @{
AVFormatIDKey : [NSNumber numberWithInt:kAudioFormatLinearPCM],
AVLinearPCMBitDepthKey : @16,
AVLinearPCMIsBigEndianKey : @NO,
AVLinearPCMIsFloatKey : @NO,
AVLinearPCMIsNonInterleaved : @NO
};

AVAssetReaderTrackOutput *output = [[AVAssetReaderTrackOutput alloc] initWithTrack:songTrack outputSettings:outputSettingsDict];
output.alwaysCopiesSampleData = NO;
Expand All @@ -176,15 +176,14 @@ - (BOOL)readTimeRange:(CMTimeRange)timeRange width:(CGFloat)width error:(NSError
NSUInteger bigSampleCount = 0;
NSMutableData *data = [NSMutableData new];
UInt32 bytesPerInputSample = 2 * channelCount;

CGFloat currentX = 0;

while (reader.status == AVAssetReaderStatusReading) {
CMSampleBufferRef sampleBufferRef = [output copyNextSampleBuffer];

if (sampleBufferRef) {
CMBlockBufferRef blockBufferRef = CMSampleBufferGetDataBuffer(sampleBufferRef);
size_t bufferLength = CMBlockBufferGetDataLength(blockBufferRef);

char *dataPointer;
CMBlockBufferGetDataPointer(blockBufferRef, 0, &bufferLength, nil, &dataPointer);

Expand All @@ -207,7 +206,6 @@ - (BOOL)readTimeRange:(CMTimeRange)timeRange width:(CGFloat)width error:(NSError

[data appendBytes:&averageSample length:(sizeof(float))];

currentX++;
bigSample = 0;
bigSampleCount = 0;
}
Expand Down
19 changes: 2 additions & 17 deletions Sources/SCWaveformView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,8 @@
@property (assign, nonatomic) CMTime progressTime;
@property (assign, nonatomic) BOOL antialiasingEnabled;

@property (assign, nonatomic) BOOL needsDisplayOnProgressTimeChange;

@property (assign, nonatomic) CMTimeRange timeRange;

@end


//typedef enum : NSUInteger {
// /**
// The WaveformView draw manually in "drawRect:" method.
// This is the fastest way to render the waveform.
//
// */
// SCWaveformViewRenderingModeDraw,
//
// /**
// The WaveformView render the waveform in UIImage's.
// This is slower, however it will be.
//
// */
// SCWaveformViewRenderingModeGenImages
//} SCWaveformViewRenderingMode;
7 changes: 6 additions & 1 deletion Sources/SCWaveformView.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
}

- (void)commonInit {
_needsDisplayOnProgressTimeChange = YES;
self.normalColor = [UIColor blueColor];
self.progressColor = [UIColor redColor];
_timeRange = CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity);
_progressTime = kCMTimeZero;

_cache = [SCWaveformCache new];
}
Expand Down Expand Up @@ -151,7 +153,10 @@ - (void)setAsset:(AVAsset *)asset {

- (void)setProgressTime:(CMTime)progressTime {
_progressTime = progressTime;
[self setNeedsDisplay];

if (self.needsDisplayOnProgressTimeChange) {
[self setNeedsDisplay];
}
}

- (void)setAntialiasingEnabled:(BOOL)antialiasingEnabled {
Expand Down