This documentation provides detailed information about the AUMediaPlayer library, which is a powerful tool for media playback in iOS applications.
Getting Started
Installation
- Start by adding the AUMediaPlayer library to your Xcode project.
- You can do this by either:
- Using CocoaPods, by adding
pod 'AUMediaPlayer'
to your Podfile and runningpod install
. - Manually adding the library files to your project.
- Once the library is added, import it in your source files:
#import <AUMediaPlayer/AUMediaPlayer.h>
.
Setup
Before using the AUMediaPlayer library, you need to set it up by performing the following steps:
- Create an instance of
AUMediaPlayerController
. - Set the media player’s delegate to receive relevant callbacks.
Here’s an example of the setup process:
AUMediaPlayerController *mediaPlayer = [[AUMediaPlayerController alloc] init];
mediaPlayer.delegate = self;
Media Playback
Loading Media
To load media for playback, follow these steps:
- Create an instance of
AUMediaItem
for each media item. - Set the necessary properties (such as URL, title, or artist) for the media item.
- Use the
loadMediaItems:
method on the media player instance to load the media items.
Here’s an example of loading media items:
AUMediaItem *mediaItem1 = [[AUMediaItem alloc] init];
mediaItem1.title = @"Song 1";
mediaItem1.artist = @"Artist 1";
mediaItem1.URL = [NSURL URLWithString:@"http://example.com/song1.mp3"];
AUMediaItem *mediaItem2 = [[AUMediaItem alloc] init];
mediaItem2.title = @"Song 2";
mediaItem2.artist = @"Artist 2";
mediaItem2.URL = [NSURL URLWithString:@"http://example.com/song2.mp3"];
[mediaPlayer loadMediaItems:@[mediaItem1, mediaItem2]];
Playback Control
The AUMediaPlayer library provides several methods to control playback:
play
: Starts playback of the loaded media.pause
: Pauses the currently playing media.stop
: Stops playback and resets the media player.seekToTime:
: Jumps to the specified playback time.
Here’s an example of controlling media playback:
[mediaPlayer play];
// After a certain time
[mediaPlayer pause];
// When playback is finished
[mediaPlayer stop];
Responding to Playback Events
To respond to different playback events, implement the AUMediaPlayerDelegate
protocol methods. These methods will be called by the media player to notify you of the playback status.
- (void)mediaPlayerDidStartPlaying:(AUMediaPlayerController *)mediaPlayer;
- (void)mediaPlayerDidPause:(AUMediaPlayerController *)mediaPlayer;
- (void)mediaPlayerDidStop:(AUMediaPlayerController *)mediaPlayer;
- (void)mediaPlayerDidFinishPlayback:(AUMediaPlayerController *)mediaPlayer;
Customization
Theming
To customize the appearance of the media player, you can make use of the provided theming options. The AUMediaPlayer library supports the following theming properties:
tintColor
: The color used for player controls.backgroundColor
: The background color of the media player.titleColor
: The color of the media title.artistColor
: The color of the artist or album name.progressColor
: The color of the playback progress bar.
Here’s an example of customizing the media player’s appearance:
mediaPlayer.tintColor = [UIColor redColor];
mediaPlayer.backgroundColor = [UIColor blackColor];
mediaPlayer.titleColor = [UIColor whiteColor];
mediaPlayer.artistColor = [UIColor grayColor];
mediaPlayer.progressColor = [UIColor cyanColor];