This repository has been archived by the owner on Aug 14, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Added JSQAudioMediaItem class #1495
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba466e7
Added JSQAudioMediaItem class
218eba9
added code to change the sound category to AVAudioSessionCategoryPlay…
67ffd80
Merged two methods in JSQAudioMediaItemDelegate, made non-optional
177db77
Merge branch 'develop' into audioMedia
eliburke dddacde
Merge branch 'develop' into audioMedia
c692917
Split view config out into a separate JSQAudioMediaViewAttributes class
e820f77
Merge branch 'audioMedia' of https://github.com/eliburke/JSQMessagesV…
975d4b7
Merge branch 'develop' into audioMedia
eliburke 311c157
Added JSQAudioMediaItem class
d65843f
Merge branch 'audioMedia' of https://github.com/eliburke/JSQMessagesV…
eliburke File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Created by Jesse Squires | ||
// http://www.jessesquires.com | ||
// | ||
// | ||
// MIT License | ||
// Copyright (c) 2014 Jesse Squires | ||
// http://opensource.org/licenses/MIT | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "JSQAudioMediaItem.h" | ||
|
||
@interface JSQAudioMediaItemTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation JSQAudioMediaItemTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
[super tearDown]; | ||
} | ||
|
||
- (void)testAudioItemInit | ||
{ | ||
JSQAudioMediaItem *item = [[JSQAudioMediaItem alloc] initWithData:[NSData data]]; | ||
XCTAssertNotNil(item); | ||
} | ||
|
||
- (void)testAudioItemIsEqual | ||
{ | ||
NSString * sample = [[NSBundle mainBundle] pathForResource:@"jsq_messages_sample" ofType:@"m4a"]; | ||
JSQAudioMediaItem *item = [[JSQAudioMediaItem alloc] initWithData:[NSData dataWithContentsOfFile:sample]]; | ||
|
||
JSQAudioMediaItem *copy = [item copy]; | ||
|
||
XCTAssertEqualObjects(item, copy, @"Copied items should be equal"); | ||
|
||
XCTAssertEqual([item hash], [copy hash], @"Copied item hashes should be equal"); | ||
|
||
XCTAssertEqualObjects(item, item, @"Item should be equal to itself"); | ||
} | ||
|
||
- (void)testAudioItemArchiving | ||
{ | ||
NSString * sample = [[NSBundle mainBundle] pathForResource:@"jsq_messages_sample" ofType:@"m4a"]; | ||
JSQAudioMediaItem *item = [[JSQAudioMediaItem alloc] initWithData:[NSData dataWithContentsOfFile:sample]]; | ||
|
||
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:item]; | ||
|
||
JSQAudioMediaItem *unarchivedItem = [NSKeyedUnarchiver unarchiveObjectWithData:data]; | ||
|
||
XCTAssertEqualObjects(item, unarchivedItem); | ||
} | ||
|
||
- (void)testMediaDataProtocol | ||
{ | ||
JSQAudioMediaItem *item = [[JSQAudioMediaItem alloc] initWithData:nil]; | ||
|
||
XCTAssertTrue(!CGSizeEqualToSize([item mediaViewDisplaySize], CGSizeZero)); | ||
XCTAssertNotNil([item mediaPlaceholderView]); | ||
XCTAssertNil([item mediaView], @"Media view should be nil if image is nil"); | ||
|
||
NSString * sample = [[NSBundle mainBundle] pathForResource:@"jsq_messages_sample" ofType:@"m4a"]; | ||
item.audioData = [NSData dataWithContentsOfFile:sample]; | ||
|
||
XCTAssertNotNil([item mediaView], @"Media view should NOT be nil once item has media data"); | ||
} | ||
|
||
@end |
Binary file added
BIN
+1.64 KB
JSQMessagesViewController/Assets/JSQMessagesAssets.bundle/Images/pause.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.42 KB
JSQMessagesViewController/Assets/JSQMessagesAssets.bundle/Images/pause@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.3 KB
JSQMessagesViewController/Assets/JSQMessagesAssets.bundle/Images/pause@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// JSQAudioMediaItem.h | ||
// | ||
|
||
#import "JSQMediaItem.h" | ||
|
||
#import "AVFoundation/AVFoundation.h" | ||
|
||
@class JSQAudioMediaItem; | ||
@protocol JSQAudioMediaItemDelegate <NSObject> | ||
@optional | ||
|
||
/* didChangeOriginalAudioCategory is called if JSQAudioMediaItem changes the sound category or categoryOptions */ | ||
- (void)audioMediaItem:(JSQAudioMediaItem*)audioMediaItem didChangeOriginalAudioCategory:(NSString *)category originalOptions:(AVAudioSessionCategoryOptions)options; | ||
|
||
/* didNotChangeCategory is called if JSQAudioMediaItem fails to change the category or categoryOptions */ | ||
- (void)audioMediaItem:(JSQAudioMediaItem*)audioMediaItem didNotChangeCategory:(NSError*)error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be a single method? audioMediaItem: didChangeAudioCategory: initialOptions: error: |
||
|
||
@end | ||
|
||
/** | ||
* The `JSQAudioMediaItem` class is a concrete `JSQMediaItem` subclass that implements the `JSQMessageMediaData` protocol | ||
* and represents a video media message. An initialized `JSQAudioMediaItem` object can be passed | ||
* to a `JSQMediaMessage` object during its initialization to construct a valid media message object. | ||
* You may wish to subclass `JSQAudioMediaItem` to provide additional functionality or behavior. | ||
*/ | ||
@interface JSQAudioMediaItem : JSQMediaItem <JSQMessageMediaData, AVAudioPlayerDelegate, NSCoding, NSCopying> | ||
|
||
/** | ||
* delegate used for notification of audio events | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
@property (nonatomic, weak) id<JSQAudioMediaItemDelegate> delegate; | ||
|
||
/** | ||
* The URL that identifies a video resource. | ||
*/ | ||
@property (nonatomic, strong) NSURL *audioURL; | ||
|
||
/** | ||
* An NSData object that contains an audio resource. | ||
*/ | ||
@property (nonatomic, strong) NSData *audioData; | ||
|
||
/** | ||
* A boolean value that specifies whether or not the audio is ready to be played. | ||
* | ||
* @discussion When set to `YES`, the audio is ready. When set to `NO` it is not ready. | ||
*/ | ||
@property (nonatomic, assign) BOOL isReadyToPlay; | ||
|
||
/** | ||
* A UIImage to be used for the play button. A default value will be used if not set. | ||
*/ | ||
@property (strong, nonatomic) UIImage * playButtonImage; | ||
|
||
/** | ||
* A UIImage to be used for the pause button. A default value will be used if not set. | ||
*/ | ||
@property (strong, nonatomic) UIImage * pauseButtonImage; | ||
|
||
/** | ||
* A UIFont to be used for the elapsed time label. A system font will be used if not set. | ||
*/ | ||
@property (strong, nonatomic) UIFont * labelFont; | ||
|
||
/** | ||
* A UIColor to be used for the player's background. | ||
*/ | ||
@property (strong, nonatomic) UIColor * backgroundColor; | ||
|
||
/** | ||
* A UIColor to be used for the player's tint. | ||
*/ | ||
@property (strong, nonatomic) UIColor * tintColor; | ||
|
||
/** | ||
* UIEdgeInsets used to determine padding around the play/pause button and timer label | ||
*/ | ||
@property (nonatomic) UIEdgeInsets controlInsets; | ||
|
||
/** | ||
* CGFloat used to determine padding between the button, progress bar, and label | ||
*/ | ||
@property (nonatomic) CGFloat controlPadding; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's bundle up everything from This class can then own a config and apply it to the view. |
||
|
||
/** | ||
* Audio Category set prior to playback. Original value | ||
*/ | ||
@property (nonatomic) NSString * audioCategory; | ||
|
||
/** | ||
* Audio Category options set prior to playback | ||
*/ | ||
@property (nonatomic) AVAudioSessionCategoryOptions audioCategoryOptions; | ||
|
||
/** | ||
* Initializes and returns an audio media item having the given audioURL. | ||
* | ||
* @param audioURL The URL that identifies the audio resource. | ||
* @param isReadyToPlay A boolean value that specifies if the audio is ready to play. | ||
* | ||
* @return An initialized `JSQAudioMediaItem` if successful, `nil` otherwise. | ||
* | ||
* @discussion If the audio must be downloaded from the network, | ||
* you may initialize a `JSQAudioMediaItem` with a `nil` audioURL or specify `NO` for | ||
* isReadyToPlay. Once the audio has been saved to disk, or is ready to stream, you can | ||
* set the audioURL property or isReadyToPlay property, respectively. | ||
*/ | ||
- (instancetype)initWithURL:(NSURL *)audioURL isReadyToPlay:(BOOL)isReadyToPlay; | ||
|
||
/** | ||
* Initializes and returns a audio media item having the given audioData. | ||
* | ||
* @param audioData The data object that contains the audio resource. | ||
* | ||
* @return An initialized `JSQAudioMediaItem` if successful, `nil` otherwise. | ||
* | ||
* @discussion If the audio must be downloaded from the network, | ||
* you may initialize a `JSQVideoMediaItem` with a `nil` audioData. | ||
* Once the audio is available you can set the file data property. | ||
*/ | ||
- (instancetype)initWithData:(NSData *)fileData; | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make these non-optional