對FreeStreamer的單例形式封裝

2021-07-22 22:13:01 字數 2814 閱讀 5954

直接**吧,注釋已經加好。

.h 檔案如下

//

// freestreamerplayer.h

// downloadlist

//// created by puslar on 16/9/18.

//#import #import "fsaudiostream.h"

@protocol playerdelegate @optional

/** *

* @param currentposition 當前位置

* @param endposition 結束位置(總時長)

*/- (void)updateprogresswithcurrentposition:(fsstreamposition)currentposition andendposition:(fsstreamposition)endposition;

@end

@inte***ce freestreamerplayer : fsaudiostream

/** */

@property (assign, nonatomic) bool isplay;

/** */

@property (assign, nonatomic) bool isloop;

/** */

@property (strong, nonatomic) nsmutablearray * audioarray;

/** */

@property (assign, nonatomic) float rate;

/** */

@property (weak, nonatomic) idplayerdelegate;

/** *

*/+ (instancetype)defaultplayer;

/** *

* @param itemindex 指定的檔案的索引

*/- (void)playitematindex:(nsuinteger)itemindex;

@end

.m檔案如下

//

// freestreamerplayer.m

// downloadlist

//// created by puslar on 16/9/18.

//#import "freestreamerplayer.h"

@inte***ce freestreamerplayer ()

@property (assign, nonatomic) nsuinteger currentitemindex;

@property (strong, nonatomic) nstimer * progresstimer;

@end

@implementation freestreamerplayer

/** *

*/+ (instancetype)defaultplayer

; player.oncompletion=^();

player.onstatechange=^(fsaudiostreamstate state)

if (state == kfsaudiostreamstopped)

if (!player.issingleplay && player.currentitemindex+1 < player.audioarray.count)

if (!player.issingleplay && player.isloop && player.currentitemindex+1 >= player.audioarray.count) }};

[player setvolume:0.5];

player.progresstimer = nil;

player.issingleplay = yes;

player.isloop = no;

player.rate = 1;

});return player;

}/**

*/- (void)play

_isplay = yes;

}/**

* * @param url 檔案位址

*/- (void)playfromurl:(nsurl *)url

_currentitemindex = [self.audioarray indexofobject:url];

if (!_progresstimer)

_isplay = yes;

}/**

* * @param offset 起始偏移量

*/- (void)playfromoffset:(fsseekbyteoffset)offset

_isplay = yes;

}/**

* * @param itemindex 指定的檔案的索引

*/- (void)playitematindex:(nsuinteger)itemindex

else

}/**

* 暫停

*/- (void)pause

}}/**

* 停止

*/- (void)stop

/** *

*/- (void)setrate:(float)rate

/** */

- (void)updateprogress

}/**

* */

- (nsmutablearray *)audioarray

return _audioarray;

}@end

對單例的理解

在objective c中要實現乙個單例類,至少需要做以下四個步驟 1 為單例物件實現乙個靜態例項,並初始化,然後設定為nil static student st nil 2 實現乙個例項構造方法檢查上面宣告的靜態例項是否為nil,如果為nil就新建並返回乙個本類的例項,student sharei...

對單鏈表的操作

include include typedef struct lnodelnode,linklist void createlist linklist l,int n p next null void getelem linklist l,int i,int e if p j i return pr...

對單例的認知

最近看到了 單例 這塊,簡單記錄下 單例就是該類只能返回乙個例項。單例所具備的特點 1.私有化的建構函式 2.私有的靜態的全域性變數 3.公有的靜態的方法 單例分為 懶漢式 餓漢式和雙層鎖式 餓漢式 先初始化物件 single類一進記憶體,就已經建立好了物件 public class singlet...