In this part of tutorial, I am going to write an iOS application that plays remote audios with functions we listed at last post.
And will talk about the essential concepts of HysteriaPlayer.
In part 0, what we want? why HysteriaPlayer?
In part 1, demonstrating how to play remote audios with HysteriaPlayer.
In part 2, making a simple player user interface.
In part 3, registering lock screen details and remote controls.
You can download source code here with branch
HysteriaPlayer can be installed and configured on CocoaPods which is an dependency manager for Objective-C projects.
I highly recommend using CocoaPods to help you scale your project.
It's elegant, clever and make your project maintainable.
If you are not familiar with CocoaPods, check offical guides, you should take a look at Getting Started for installing CocoaPods and Using CocoaPods for understanding the flows of dependencies management of CocoaPods.
When you successfully installed CocoaPods, launch your terminal and run
pod search hysteriaplayer, it will list versions of HysteriaPlayer that available.
Create or open your
Podfile and insert this line into it. (newest version of HysteriaPlayer instead of x.x.x)
pod 'HysteriaPlayer', `~> x.x.x`
pod install and there you go.
One last thing to do, select your application target in Xcode, in the Capabilities tab enable Audio and AirPlay checkbox inside Background Modes field. Applications without registered background playable can't play or stream audio when app isn't in foregrond or device locked.
How to use
I started a new project, added two buttons in xib. That's it.
There's a huge update for HysteriaPlayer from 1.x to 2.x, this tutorial targeted on 2.x.
Now following step by step tutorials:
HysteriaPlayerManager as following Set-up.
Song is our model object.
PlayingItems is the queue system for HysteriaPlayer.
registerHandlerFailed: are optional event callbacks.
Create a PlayingItems class extends
NSObject, we will store our queues there. Ensuring that only one instance of a PlayingItems is created, PlayingItems should implement singleton pattern.
Ready to go
To starting a new playback, you have to renew HysteriaPlayer's data source by
setupSourceGetter:ItemsCount: method by
responseObject is what iTunes API responsed, in this tutorial we searching fo U2 and Jack Johnson.
When buttons tapped, change the API endpoint and everythings done.
You should hear music playing now, dead simple.
next post: Streaming remote audio on iOS with HysteriaPlayer Tutorial (2)