IOS Github open source framework StreamingKit network music player simply started (1)

  • StreamingKit because Apple does not own the music flow framework, if you need to play streaming audio, write your own words to understand a lot of audio decoding and the like, this is a very detailed explanation of http://msching.github.io NetEase cloud music developers, but a short time is difficult to chew, so it is recommended to use third party framework!
  • Third party audio frame
  • StreamingKit is what we need
  • GitHub:https://github.com/tumtumtum/StreamingKit
    DOUAudioStreamer our domestic open source music player
    GitHub:https://github.com/douban/DOUAudioStreamer
    bean FreeStreamer
    GitHub:https://github.com/muhku/ FreeStreamer
    more than Star in more than 1000, can be stabilized using
    Jukebox Swift version of this framework is
    : https://github.com/teodorpatras/Jukebox: GitHub

  • We need to have
    1 can play a music streaming music stream basic function framework (to a web site can play URL)
    2
    3 – pause playback speed is too slow, the cache music prompt
    4 total acquisition time is
    audio playback time and a song can fast forward to want to play 5 the time points above is one of the most basic function framework.

The zeroth step, pod lead StreamingKit

Upper code:

Step 1 AppDelegate.m:

#import < AVFoundation/AVFoundation.h> / / remember import with frame - (BOOL) application: (UIApplication*) application didFinishLaunchingWithOptions: (NSDictionary* launchOptions) {//1 to initialize the iPod, use some play mode. NSError* error; [[AVAudioSession sharedInstance] error]; [[AVAudioSession setCategory:AVAudioSessionCategoryPlayback error:& sharedInstance] setActive:YES error:& error]; return YES;}

The second step to initialize a controller:

#import "ViewController.h" #import "STKAudioPlayer.h" @interface (ViewController) < STKAudioPlayerDelegate> STKAudioPlayer* {audioPlayer; / / NSTimer* timer @end} save properties; @implementation ViewController - (void) viewDidLoad {[super viewDidLoad]; / / / initialize a player audioPlayer = [[STKAudioPlayer alloc] init]; / / / to a URL string, and began to play music [audioPlayer play:@ "http://mxd.766.com/sdo/music/data/3/m10.mp3"]; / / / set proxy audioPlayer.delegate = self; [self setupTimer];} / / can open a timer - (void) setupTimer [NSTimer timerWithTimeInterval:0.1 target:self {timer = selector:@selector (tick) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];} / / this method every 0 seconds timer is a call - (void) tick {/ / get the current audio playback time total time int duration = audioPlayer.duration; NSLog (@ "%d", duration); the current playback time of int / / progress = audioPlayer.progress; NSLog (@ "%d", progress); if (audioPlayer.state = = STKAudioPlayerStateBuffering) {NSLog (@ "buffer");}} / / pause and play - (void playButtonPressed) {if (audioPlayer.state = = STKAudioPlayerStatePaused) {/ / [audioPlayer resume] else} recovery songs; the song [audioPlayer pause] {/ / pause}}; / / change songs broadcast schedule (void changedTime) {/ / manual makes the songs to play music from tenth seconds. [audioPlayer seekToTime:10];} / / / called when the player changes state, stop and start playing will call - (void) audioPlayer: (STKAudioPlayer*) audioPlayer stateChanged: (STKAudioPlayerState) state previousState: (STKAudioPlayerState previousState) {} / / / accidents and the possible occurrence of an unrecoverable error, rarely called probability. This song is not loaded, or URL is not available - (void) audioPlayer: (STKAudioPlayer*) audioPlayer unexpectedError: (STKAudioPlayerErrorCode) {errorCode} / / / when a project starts playing call - (void) audioPlayer: (STKAudioPlayer*) audioPlayer didStartPlayingQueueItemId: (NSObject* queueItemId) {} / / the end of song is generally 5 seconds ahead of the call - (void) audioPlayer: (STKAudioPlayer*) audioPlayer didFinishBufferingSourceWithQueueItemId: (NSObject* queueItemId) {} / / / when a project is completed, is called - (void) audioPlayer: (STKAudioPlayer*) audioPlayer didFinishPlayingQueueItemId: (NSObject*) queueItemId withReason: (STKAudioPlayerStopReason) stopRe ASON andProgress: (double) progress andDuration: (double) duration {} @end
The above has put the basic use of a music third party framework summary!

And how to play music in the background? A picture to understand
http://www.jianshu.com/p/db07eaab6258

What if there is a problem, can low beam contact me at the same table. Any message

  • I look so cute n (aged at less than n)
  • Pay attention to my meager (Liang Tongzhuo):http://weibo.com/tongrenyinsheng
  • Personal blog: http://www.liangtongzhuo.com
  • IOS personal written app (such as dream ASMR) ASMR music