@@ -13,6 +13,7 @@ @interface BubblePlayView ()
1313@property (nonatomic , strong ) UIImageView *bgImageView;
1414@property (nonatomic , strong ) UIImageView *playImageView;
1515@property (nonatomic , strong ) UILabel *durationLbl;
16+ @property (nonatomic , strong ) UIActivityIndicatorView *activityView;
1617
1718@end
1819
@@ -33,6 +34,12 @@ - (instancetype)initWithFrame:(CGRect)frame {
3334 _durationLbl.textColor = [UIColor blackColor ];
3435 [self addSubview: _durationLbl];
3536
37+ _activityView = [[UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray];
38+ _activityView.center = CGPointMake (self.frame .size .width /2 , self.frame .size .height /2 );
39+ _activityView.hidesWhenStopped = YES ;
40+ [_activityView stopAnimating ];
41+ [self addSubview: _activityView];
42+
3643 self.showBgImg = YES ;
3744 self.type = BubbleTypeLeft;
3845 self.duration = 0 ;
@@ -90,53 +97,57 @@ - (void)setShowBgImg:(BOOL)showBgImg {
9097 _bgImageView.hidden = !showBgImg;
9198}
9299
100+ #pragma mark - Animation
101+
102+ - (void )startPlayingAnimation {
103+ if (_type == BubbleTypeRight) {
104+ _playImageView.image = [UIImage animatedImageWithImages: @[[UIImage imageNamed: @" btn_file_cancel" ], [UIImage imageNamed: @" btn_file_reDo" ], [UIImage imageNamed: @" button_download_cancel" ]] duration: 0.8 ];
105+ }
106+ else {
107+ _playImageView.image = [UIImage animatedImageWithImages: @[[UIImage imageNamed: @" btn_file_cancel" ], [UIImage imageNamed: @" btn_file_reDo" ], [UIImage imageNamed: @" button_download_cancel" ]] duration: 0.8 ];
108+ }
109+ [_playImageView startAnimating ];
110+ }
111+
112+ - (void )stopPlayingAnimation {
113+ [_playImageView stopAnimating ];
114+ if (_type == BubbleTypeRight) {
115+ _playImageView.image = [UIImage imageNamed: @" add_user_icon" ];
116+ }
117+ else {
118+ _playImageView.image = [UIImage imageNamed: @" add_user_icon" ];
119+ }
120+ }
121+
93122#pragma mark - Download
94123
95124- (void )didDownloadStarted {
96-
125+ [_activityView startAnimating ];
97126}
98127
99128- (void )didDownloadFinished {
100-
129+ [_activityView stopAnimating ];
101130}
102131
103132- (void )didDownloadError : (NSError *)error {
104-
133+ [_activityView stopAnimating ];
105134}
106135
107136#pragma mark - AudioManagerDelegate
108137
109138- (void )didAudioPlayStarted : (AudioManager *)am {
110139 [super didAudioPlayStarted: am];
111- // if (_type == BubbleTypeRight) {
112- // _playImageView.image = [UIImage animatedImageNamed:@"bubble_right_playing_" duration:1];
113- // }
114- // else {
115- // _playImageView.image = [UIImage animatedImageNamed:@"bubble_left_playing_" duration:1];
116- // }
117- // [_playImageView startAnimating];
140+ [self startPlayingAnimation ];
118141}
119142
120143- (void )didAudioPlayStoped : (AudioManager *)am successfully : (BOOL )successfully {
121144 [super didAudioPlayStoped: am successfully: successfully];
122- [_playImageView stopAnimating ];
123- if (_type == BubbleTypeRight) {
124- _playImageView.image = [UIImage imageNamed: @" add_user_icon" ];
125- }
126- else {
127- _playImageView.image = [UIImage imageNamed: @" add_user_icon" ];
128- }
145+ [self stopPlayingAnimation ];
129146}
130147
131148- (void )didAudioPlay : (AudioManager *)am err : (NSError *)err {
132149 [super didAudioPlay: am err: err];
133- [_playImageView stopAnimating ];
134- if (_type == BubbleTypeRight) {
135- _playImageView.image = [UIImage imageNamed: @" add_user_icon" ];
136- }
137- else {
138- _playImageView.image = [UIImage imageNamed: @" add_user_icon" ];
139- }
150+ [self stopPlayingAnimation ];
140151}
141152
142153@end
0 commit comments