DKAudioPlayer
DKAudioPlayer copied to clipboard
Simple drop in audio player component for iOS
DKAudioPlayer
Audio player component for iOS (both iPhone and iPad) with neat and flexible interface design. It can be added as a header view to the table view.
GIF demo
Youtube demo
ScreenShot
Requirements
Tested on iOS 9 and higher. But probably it supports iOS 6 and higher.
Installation
DKAudioPlayer is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'DKAudioPlayer'
How to use
There is a sample project of a universal app for iPhone and iPad. Player can stretch to the width of a parent View Controller.
First you create an instance of a player object:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:@"sample.mp3" ofType:nil];
if ( audioFilePath ) {
// The width of a player is equal to the width of a parent view
self.audioPlayer = [[DKAudioPlayer alloc] initWithAudioFilePath:audioFilePath width:self.view.frame.size.width height:0];
// Setting the origin of an audio player
CGRect frame = self.audioPlayer.frame;
frame.origin = CGPointMake(0, self.view.frame.size.height - self.tabBarController.tabBar.frame.size.height);
self.audioPlayer.frame = frame;
// Adding player on a view
[self.view addSubview:self.audioPlayer];
}
}
Then on some action you can just show or hide the player:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (! self.audioPlayer.isVisible) {
[self.audioPlayer showAnimated:YES];
}
}
- (IBAction)showHideClicked:(id)sender
{
if (self.audioPlayer.isVisible) {
[self.audioPlayer hideAnimated:YES];
}
else {
[self.audioPlayer showAnimated:YES];
}
}
It works in background if you add this to your application plist file:
Required background modes = App plays audio or streams audio/video using AirPlay
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
Author
Denis Kutlubaev, [email protected]
License
DKAudioPlayer is available under the MIT license. See the LICENSE file for more info.