Commit 5ef3a43104a28882f0a76c9009df6e1884d2c649

Authored by 王军波
1 parent aea4fd7d

cell添加加载视图,播放器,创建model

LiveVideoCloud/LiveVideoCloud.xcodeproj/project.pbxproj
@@ -186,9 +186,10 @@ @@ -186,9 +186,10 @@
186 D2888DB11E6EC05F003A77C8 /* TempViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888DB01E6EC05F003A77C8 /* TempViewController.m */; }; 186 D2888DB11E6EC05F003A77C8 /* TempViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888DB01E6EC05F003A77C8 /* TempViewController.m */; };
187 D2888DB41E6EC154003A77C8 /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888DB31E6EC154003A77C8 /* HomeViewController.m */; }; 187 D2888DB41E6EC154003A77C8 /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888DB31E6EC154003A77C8 /* HomeViewController.m */; };
188 D2888DB71E6EC1B8003A77C8 /* LVCMyViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888DB61E6EC1B8003A77C8 /* LVCMyViewController.m */; }; 188 D2888DB71E6EC1B8003A77C8 /* LVCMyViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888DB61E6EC1B8003A77C8 /* LVCMyViewController.m */; };
189 - D29E81ED1E88DC5B008C9906 /* PriChatCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D29E81EC1E88DC5B008C9906 /* PriChatCell.m */; };  
190 D29D88481E88C53300543A03 /* LVCUGCLivePrepareView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29D88471E88C53300543A03 /* LVCUGCLivePrepareView.m */; }; 189 D29D88481E88C53300543A03 /* LVCUGCLivePrepareView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29D88471E88C53300543A03 /* LVCUGCLivePrepareView.m */; };
  190 + D29E81ED1E88DC5B008C9906 /* PriChatCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D29E81EC1E88DC5B008C9906 /* PriChatCell.m */; };
191 D2A089E81E89FA720071412C /* LVCUGCLivePlayerCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A089E71E89FA720071412C /* LVCUGCLivePlayerCell.m */; }; 191 D2A089E81E89FA720071412C /* LVCUGCLivePlayerCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A089E71E89FA720071412C /* LVCUGCLivePlayerCell.m */; };
  192 + D2A089EB1E8A09CB0071412C /* LVCUGCLivePlayerModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A089EA1E8A09CB0071412C /* LVCUGCLivePlayerModel.m */; };
192 D2A803081E80BD6F009D6F1C /* TopToolView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A803071E80BD6F009D6F1C /* TopToolView.m */; }; 193 D2A803081E80BD6F009D6F1C /* TopToolView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A803071E80BD6F009D6F1C /* TopToolView.m */; };
193 D2B2ED7A1E88F90C00F7538A /* CNLiveChatManager.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2D236B21E88F8E600B7C517 /* CNLiveChatManager.framework */; }; 194 D2B2ED7A1E88F90C00F7538A /* CNLiveChatManager.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2D236B21E88F8E600B7C517 /* CNLiveChatManager.framework */; };
194 D2B2ED7B1E88F90C00F7538A /* CNLiveChatManager.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D2D236B21E88F8E600B7C517 /* CNLiveChatManager.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 195 D2B2ED7B1E88F90C00F7538A /* CNLiveChatManager.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D2D236B21E88F8E600B7C517 /* CNLiveChatManager.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -608,12 +609,14 @@ @@ -608,12 +609,14 @@
608 D2888DB31E6EC154003A77C8 /* HomeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeViewController.m; sourceTree = "<group>"; }; 609 D2888DB31E6EC154003A77C8 /* HomeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeViewController.m; sourceTree = "<group>"; };
609 D2888DB51E6EC1B8003A77C8 /* LVCMyViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCMyViewController.h; sourceTree = "<group>"; }; 610 D2888DB51E6EC1B8003A77C8 /* LVCMyViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCMyViewController.h; sourceTree = "<group>"; };
610 D2888DB61E6EC1B8003A77C8 /* LVCMyViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCMyViewController.m; sourceTree = "<group>"; }; 611 D2888DB61E6EC1B8003A77C8 /* LVCMyViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCMyViewController.m; sourceTree = "<group>"; };
611 - D29E81EB1E88DC5B008C9906 /* PriChatCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PriChatCell.h; sourceTree = "<group>"; };  
612 - D29E81EC1E88DC5B008C9906 /* PriChatCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PriChatCell.m; sourceTree = "<group>"; };  
613 D29D88461E88C53300543A03 /* LVCUGCLivePrepareView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCUGCLivePrepareView.h; sourceTree = "<group>"; }; 612 D29D88461E88C53300543A03 /* LVCUGCLivePrepareView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCUGCLivePrepareView.h; sourceTree = "<group>"; };
614 D29D88471E88C53300543A03 /* LVCUGCLivePrepareView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCUGCLivePrepareView.m; sourceTree = "<group>"; }; 613 D29D88471E88C53300543A03 /* LVCUGCLivePrepareView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCUGCLivePrepareView.m; sourceTree = "<group>"; };
  614 + D29E81EB1E88DC5B008C9906 /* PriChatCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PriChatCell.h; sourceTree = "<group>"; };
  615 + D29E81EC1E88DC5B008C9906 /* PriChatCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PriChatCell.m; sourceTree = "<group>"; };
615 D2A089E61E89FA720071412C /* LVCUGCLivePlayerCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCUGCLivePlayerCell.h; sourceTree = "<group>"; }; 616 D2A089E61E89FA720071412C /* LVCUGCLivePlayerCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCUGCLivePlayerCell.h; sourceTree = "<group>"; };
616 D2A089E71E89FA720071412C /* LVCUGCLivePlayerCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCUGCLivePlayerCell.m; sourceTree = "<group>"; }; 617 D2A089E71E89FA720071412C /* LVCUGCLivePlayerCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCUGCLivePlayerCell.m; sourceTree = "<group>"; };
  618 + D2A089E91E8A09CB0071412C /* LVCUGCLivePlayerModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCUGCLivePlayerModel.h; sourceTree = "<group>"; };
  619 + D2A089EA1E8A09CB0071412C /* LVCUGCLivePlayerModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCUGCLivePlayerModel.m; sourceTree = "<group>"; };
617 D2A803061E80BD6F009D6F1C /* TopToolView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopToolView.h; sourceTree = "<group>"; }; 620 D2A803061E80BD6F009D6F1C /* TopToolView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopToolView.h; sourceTree = "<group>"; };
618 D2A803071E80BD6F009D6F1C /* TopToolView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopToolView.m; sourceTree = "<group>"; }; 621 D2A803071E80BD6F009D6F1C /* TopToolView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopToolView.m; sourceTree = "<group>"; };
619 D2B2ED7E1E88FC5200F7538A /* LVCUGCLiveEndView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCUGCLiveEndView.h; sourceTree = "<group>"; }; 622 D2B2ED7E1E88FC5200F7538A /* LVCUGCLiveEndView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCUGCLiveEndView.h; sourceTree = "<group>"; };
@@ -734,6 +737,8 @@ @@ -734,6 +737,8 @@
734 81A4831F1E88F4BF0097A80A /* LVCProgramModel.m */, 737 81A4831F1E88F4BF0097A80A /* LVCProgramModel.m */,
735 81A482FF1E88B0130097A80A /* LVCChatRoomModel.h */, 738 81A482FF1E88B0130097A80A /* LVCChatRoomModel.h */,
736 81A483001E88B0130097A80A /* LVCChatRoomModel.m */, 739 81A483001E88B0130097A80A /* LVCChatRoomModel.m */,
  740 + D2A089E91E8A09CB0071412C /* LVCUGCLivePlayerModel.h */,
  741 + D2A089EA1E8A09CB0071412C /* LVCUGCLivePlayerModel.m */,
737 ); 742 );
738 path = Model; 743 path = Model;
739 sourceTree = "<group>"; 744 sourceTree = "<group>";
@@ -1927,6 +1932,7 @@ @@ -1927,6 +1932,7 @@
1927 D2029CC41E6EADE10027CD92 /* UIImageView+WebCache.m in Sources */, 1932 D2029CC41E6EADE10027CD92 /* UIImageView+WebCache.m in Sources */,
1928 D236967E1E7F9E4100E4BF71 /* GiftPayButton.m in Sources */, 1933 D236967E1E7F9E4100E4BF71 /* GiftPayButton.m in Sources */,
1929 81A483081E88B6140097A80A /* UIView+ViewController.m in Sources */, 1934 81A483081E88B6140097A80A /* UIView+ViewController.m in Sources */,
  1935 + D2A089EB1E8A09CB0071412C /* LVCUGCLivePlayerModel.m in Sources */,
1930 D2029CC81E6EADE10027CD92 /* SVProgressAnimatedView.m in Sources */, 1936 D2029CC81E6EADE10027CD92 /* SVProgressAnimatedView.m in Sources */,
1931 D2029C961E6EADE10027CD92 /* MBProgressHUD.m in Sources */, 1937 D2029C961E6EADE10027CD92 /* MBProgressHUD.m in Sources */,
1932 810B65071E779B1F00133E15 /* ViewController+MASAdditions.m in Sources */, 1938 810B65071E779B1F00133E15 /* ViewController+MASAdditions.m in Sources */,
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/Controller/LVCUGCLivePlayerController.m
@@ -18,8 +18,6 @@ static NSString *cellId = @&quot;cellId&quot;; @@ -18,8 +18,6 @@ static NSString *cellId = @&quot;cellId&quot;;
18 18
19 @property (nonatomic, strong) UICollectionView *collectionView; 19 @property (nonatomic, strong) UICollectionView *collectionView;
20 20
21 -@property (nonatomic, strong) CNLiveMoviePlayerController *player;// 播放器  
22 -  
23 @property (nonatomic, strong) LVCUGCBackgroundView *bgView; // 背景视图 21 @property (nonatomic, strong) LVCUGCBackgroundView *bgView; // 背景视图
24 22
25 @end 23 @end
@@ -48,205 +46,6 @@ static NSString *cellId = @&quot;cellId&quot;; @@ -48,205 +46,6 @@ static NSString *cellId = @&quot;cellId&quot;;
48 [self.view addSubview:self.bgView]; 46 [self.view addSubview:self.bgView];
49 [self.view addSubview:self.collectionView]; 47 [self.view addSubview:self.collectionView];
50 48
51 - //添加播放器通知  
52 - [self installMovieNotificationObservers];  
53 -  
54 - //直播播放  
55 - _player = [[CNLiveMoviePlayerController alloc] initLivePlayWithChannelId:@"iOStest"  
56 - authSuccess:^{  
57 -  
58 - _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO;  
59 - _player.view.frame = self.view.bounds;  
60 - _player.shouldAutoplay = YES;  
61 - [_player prepareToPlay];  
62 - [self.view addSubview:_player.view];  
63 - [self.view sendSubviewToBack:_player.view];  
64 -  
65 - } authFailed:^(NSDictionary *errorInfo) {  
66 - NSLog(@"初始化直播播放器失败:%@", errorInfo);  
67 -  
68 -  
69 - } getAnchorStatusResult:^(BOOL result) {  
70 -  
71 - NSLog(@"-------------获取主播状态%d", result ? YES : NO);  
72 -  
73 - }];  
74 -}  
75 -  
76 -#pragma mark - 添加通知监听 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
77 --(void)installMovieNotificationObservers //添加视频播放通知  
78 -{  
79 - //视频加载状态改变  
80 - [[NSNotificationCenter defaultCenter] addObserver:self  
81 - selector:@selector(loadStateDidChange:)  
82 - name:MPMoviePlayerLoadStateDidChangeNotification  
83 - object:nil];  
84 -  
85 - //视频播放错误及结束原因  
86 - [[NSNotificationCenter defaultCenter] addObserver:self  
87 - selector:@selector(moviePlayBackDidFinish:)  
88 - name:MPMoviePlayerPlaybackDidFinishNotification  
89 - object:nil];  
90 -  
91 - //视频缓冲至可播放状态  
92 - [[NSNotificationCenter defaultCenter] addObserver:self  
93 - selector:@selector(mediaIsPreparedToPlayDidChange:)  
94 - name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification  
95 - object:nil];  
96 -  
97 - //视频播放状态改变  
98 - [[NSNotificationCenter defaultCenter] addObserver:self  
99 - selector:@selector(moviePlayBackStateDidChange:)  
100 - name:MPMoviePlayerPlaybackStateDidChangeNotification  
101 - object:nil];  
102 -  
103 -  
104 - //获取主播状态通知(点播和普通播放不需要注册该通知)  
105 - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(anchorStatusChanged:)  
106 - name:CNLiveAnchorStatusChangedNotification  
107 - object:nil];  
108 -  
109 -}  
110 -  
111 -#pragma mark - 移除通知 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
112 -- (void)removeMovieNotificationObservers  
113 -{  
114 - [[NSNotificationCenter defaultCenter]removeObserver:self  
115 - name:MPMoviePlayerLoadStateDidChangeNotification  
116 - object:nil];  
117 - [[NSNotificationCenter defaultCenter]removeObserver:self  
118 - name:MPMoviePlayerPlaybackDidFinishNotification  
119 - object:nil];  
120 - [[NSNotificationCenter defaultCenter]removeObserver:self  
121 - name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification  
122 - object:nil];  
123 - [[NSNotificationCenter defaultCenter]removeObserver:self  
124 - name:MPMoviePlayerPlaybackStateDidChangeNotification  
125 - object:nil];  
126 -  
127 - [[NSNotificationCenter defaultCenter]removeObserver:self  
128 - name:CNLiveAnchorStatusChangedNotification  
129 - object:nil];  
130 -}  
131 -  
132 -#pragma mark - 通知 Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
133 -//视频加载状态改变  
134 -- (void)loadStateDidChange:(NSNotification *)notification  
135 -{  
136 - if (_player) {  
137 - MPMovieLoadState loadState = _player.loadState;  
138 - if ((loadState & MPMovieLoadStatePlaythroughOK) != 0) {  
139 -  
140 - NSLog(@"loadStateDidChange: MPMovieLoadStatePlaythroughOK: %d\n", (int)loadState);  
141 -  
142 - } else if ((loadState & MPMovieLoadStateStalled) != 0) {  
143 - NSLog(@"loadStateDidChange: MPMovieLoadStateStalled: %d\n", (int)loadState);  
144 -  
145 - } else {  
146 - NSLog(@"loadStateDidChange: ???: %d\n", (int)loadState);  
147 - }  
148 - }  
149 -}  
150 -  
151 -//视频播放错误及结束原因  
152 -- (void)moviePlayBackDidFinish:(NSNotification *)notification  
153 -{  
154 - if (_player) {  
155 - int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];  
156 - if (MPMovieFinishReasonPlaybackError == reason) {  
157 -  
158 -  
159 - } else {  
160 -  
161 - }  
162 -  
163 - switch (reason)  
164 - {  
165 - case MPMovieFinishReasonPlaybackEnded:  
166 - NSLog(@"playbackStateDidChange: MPMovieFinishReasonPlaybackEnded: %d\n", reason);  
167 - break;  
168 -  
169 - case MPMovieFinishReasonUserExited:  
170 - NSLog(@"playbackStateDidChange: MPMovieFinishReasonUserExited: %d\n", reason);  
171 - break;  
172 -  
173 - case MPMovieFinishReasonPlaybackError:  
174 - NSLog(@"playbackStateDidChange: MPMovieFinishReasonPlaybackError: %d\n", reason);  
175 - break;  
176 -  
177 - default:  
178 - NSLog(@"playbackPlayBackDidFinish: ???: %d\n", reason);  
179 - break;  
180 - }  
181 - }  
182 -}  
183 -  
184 -//视频缓冲至可播放状态  
185 -- (void)mediaIsPreparedToPlayDidChange:(NSNotification *)notification  
186 -{  
187 - if (_player) {  
188 - NSLog(@"isPreparedToPlay");  
189 -// if (_loadingView) {  
190 -// [_loadingView removeFromSuperview];  
191 -// }  
192 - }  
193 -}  
194 -  
195 -//视频播放状态改变  
196 -- (void)moviePlayBackStateDidChange:(NSNotification *)notification  
197 -{  
198 - if (_player) {  
199 -  
200 - switch (_player.playbackState) {  
201 - case MPMoviePlaybackStateStopped: {  
202 -  
203 - NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateStopped");  
204 - break;  
205 - }  
206 - case MPMoviePlaybackStatePlaying: {  
207 -  
208 - NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStatePlaying");  
209 - break;  
210 - }  
211 - case MPMoviePlaybackStatePaused:  
212 -  
213 - NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStatePaused");  
214 - break;  
215 - case MPMoviePlaybackStateInterrupted:  
216 -  
217 - NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateInterrupted");  
218 - break;  
219 - case MPMoviePlaybackStateSeekingForward:  
220 -  
221 - NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateSeekingForward");  
222 - break;  
223 - case MPMoviePlaybackStateSeekingBackward:  
224 -  
225 - NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateSeekingBackward");  
226 - break;  
227 - default:  
228 -  
229 - NSLog(@"moviePlayBackStateDidChange : %ld", (long)_player.playbackState);  
230 - break;  
231 - }  
232 - }  
233 -}  
234 -  
235 -  
236 -  
237 -// 获取主播状态通知  
238 -- (void)anchorStatusChanged:(NSNotification *)notification  
239 -{  
240 - if (_player.anchorStatus == 2) { // 已结束  
241 -  
242 - }  
243 - _bgView.anchorStatus = _player.anchorStatus;  
244 -}  
245 -  
246 -//重新连接获取主播状态  
247 -- (void)anchorStatusConnectFailed  
248 -{  
249 -  
250 } 49 }
251 50
252 #pragma mark - UICollectionViewDelegate, UICollectionViewDataSource !!!!!!!!!!!!!!!!!!!!!!!!!!! 51 #pragma mark - UICollectionViewDelegate, UICollectionViewDataSource !!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -269,7 +68,12 @@ static NSString *cellId = @&quot;cellId&quot;; @@ -269,7 +68,12 @@ static NSString *cellId = @&quot;cellId&quot;;
269 68
270 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 69 - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
271 70
  71 + NSLog(@"一直");
  72 +}
  73 +
  74 +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
272 75
  76 + NSLog(@"停止");
273 } 77 }
274 78
275 79
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/Model/LVCUGCLivePlayerModel.h 0 → 100644
  1 +//
  2 +// LVCUGCLivePlayerModel.h
  3 +// LiveVideoCloud
  4 +//
  5 +// Created by cnliveJunBo on 17/3/28.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@interface LVCUGCLivePlayerModel : NSObject
  12 +
  13 +@end
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/Model/LVCUGCLivePlayerModel.m 0 → 100644
  1 +//
  2 +// LVCUGCLivePlayerModel.m
  3 +// LiveVideoCloud
  4 +//
  5 +// Created by cnliveJunBo on 17/3/28.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "LVCUGCLivePlayerModel.h"
  10 +
  11 +@implementation LVCUGCLivePlayerModel
  12 +
  13 +@end
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCLivePlayerCell.h
@@ -13,4 +13,6 @@ @@ -13,4 +13,6 @@
13 13
14 @property (nonatomic, strong) LVCUGCPlayerLoadingView *loadingView; 14 @property (nonatomic, strong) LVCUGCPlayerLoadingView *loadingView;
15 15
  16 +@property (nonatomic, strong) CNLiveMoviePlayerController *player; // 播放器
  17 +
16 @end 18 @end
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCLivePlayerCell.m
@@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
15 self = [super initWithFrame:frame]; 15 self = [super initWithFrame:frame];
16 if (self) { 16 if (self) {
17 self.contentView.backgroundColor = [UIColor whiteColor]; 17 self.contentView.backgroundColor = [UIColor whiteColor];
  18 +
  19 + [self installMovieNotificationObservers];
18 [self addSubview:self.loadingView]; 20 [self addSubview:self.loadingView];
19 } 21 }
20 return self; 22 return self;
@@ -29,4 +31,206 @@ @@ -29,4 +31,206 @@
29 return _loadingView; 31 return _loadingView;
30 } 32 }
31 33
  34 +- (CNLiveMoviePlayerController *)player {
  35 +
  36 + if (!_player) {
  37 + _player = [[CNLiveMoviePlayerController alloc] initLivePlayWithChannelId:@"iOStest"
  38 + authSuccess:^{
  39 +
  40 + _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO;
  41 + _player.view.frame = self.contentView.bounds;
  42 + _player.shouldAutoplay = YES;
  43 + [_player prepareToPlay];
  44 + [self.contentView addSubview:_player.view];
  45 + [self.contentView sendSubviewToBack:_player.view];
  46 +
  47 + } authFailed:^(NSDictionary *errorInfo) {
  48 + NSLog(@"初始化直播播放器失败:%@", errorInfo);
  49 +
  50 +
  51 + } getAnchorStatusResult:^(BOOL result) {
  52 +
  53 + NSLog(@"-------------获取主播状态%d", result ? YES : NO);
  54 +
  55 + }];
  56 + }
  57 + return _player;
  58 +}
  59 +
  60 +#pragma mark - 添加通知监听 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  61 +-(void)installMovieNotificationObservers //添加视频播放通知
  62 +{
  63 + //视频加载状态改变
  64 + [[NSNotificationCenter defaultCenter] addObserver:self
  65 + selector:@selector(loadStateDidChange:)
  66 + name:MPMoviePlayerLoadStateDidChangeNotification
  67 + object:nil];
  68 +
  69 + //视频播放错误及结束原因
  70 + [[NSNotificationCenter defaultCenter] addObserver:self
  71 + selector:@selector(moviePlayBackDidFinish:)
  72 + name:MPMoviePlayerPlaybackDidFinishNotification
  73 + object:nil];
  74 +
  75 + //视频缓冲至可播放状态
  76 + [[NSNotificationCenter defaultCenter] addObserver:self
  77 + selector:@selector(mediaIsPreparedToPlayDidChange:)
  78 + name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
  79 + object:nil];
  80 +
  81 + //视频播放状态改变
  82 + [[NSNotificationCenter defaultCenter] addObserver:self
  83 + selector:@selector(moviePlayBackStateDidChange:)
  84 + name:MPMoviePlayerPlaybackStateDidChangeNotification
  85 + object:nil];
  86 +
  87 +
  88 + //获取主播状态通知(点播和普通播放不需要注册该通知)
  89 + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(anchorStatusChanged:)
  90 + name:CNLiveAnchorStatusChangedNotification
  91 + object:nil];
  92 +
  93 +}
  94 +
  95 +#pragma mark - 通知 Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  96 +//视频加载状态改变
  97 +- (void)loadStateDidChange:(NSNotification *)notification
  98 +{
  99 + if (_player) {
  100 + MPMovieLoadState loadState = _player.loadState;
  101 + if ((loadState & MPMovieLoadStatePlaythroughOK) != 0) {
  102 +
  103 + NSLog(@"loadStateDidChange: MPMovieLoadStatePlaythroughOK: %d\n", (int)loadState);
  104 +
  105 + } else if ((loadState & MPMovieLoadStateStalled) != 0) {
  106 + NSLog(@"loadStateDidChange: MPMovieLoadStateStalled: %d\n", (int)loadState);
  107 +
  108 + } else {
  109 + NSLog(@"loadStateDidChange: ???: %d\n", (int)loadState);
  110 + }
  111 + }
  112 +}
  113 +
  114 +//视频播放错误及结束原因
  115 +- (void)moviePlayBackDidFinish:(NSNotification *)notification
  116 +{
  117 + if (_player) {
  118 + int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
  119 + if (MPMovieFinishReasonPlaybackError == reason) {
  120 +
  121 +
  122 + } else {
  123 +
  124 + }
  125 +
  126 + switch (reason)
  127 + {
  128 + case MPMovieFinishReasonPlaybackEnded:
  129 + NSLog(@"playbackStateDidChange: MPMovieFinishReasonPlaybackEnded: %d\n", reason);
  130 + break;
  131 +
  132 + case MPMovieFinishReasonUserExited:
  133 + NSLog(@"playbackStateDidChange: MPMovieFinishReasonUserExited: %d\n", reason);
  134 + break;
  135 +
  136 + case MPMovieFinishReasonPlaybackError:
  137 + NSLog(@"playbackStateDidChange: MPMovieFinishReasonPlaybackError: %d\n", reason);
  138 + break;
  139 +
  140 + default:
  141 + NSLog(@"playbackPlayBackDidFinish: ???: %d\n", reason);
  142 + break;
  143 + }
  144 + }
  145 +}
  146 +
  147 +//视频缓冲至可播放状态
  148 +- (void)mediaIsPreparedToPlayDidChange:(NSNotification *)notification
  149 +{
  150 + if (_player) {
  151 + NSLog(@"isPreparedToPlay");
  152 + // if (_loadingView) {
  153 + // [_loadingView removeFromSuperview];
  154 + // }
  155 + }
  156 +}
  157 +
  158 +//视频播放状态改变
  159 +- (void)moviePlayBackStateDidChange:(NSNotification *)notification
  160 +{
  161 + if (_player) {
  162 +
  163 + switch (_player.playbackState) {
  164 + case MPMoviePlaybackStateStopped: {
  165 +
  166 + NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateStopped");
  167 + break;
  168 + }
  169 + case MPMoviePlaybackStatePlaying: {
  170 +
  171 + NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStatePlaying");
  172 + break;
  173 + }
  174 + case MPMoviePlaybackStatePaused:
  175 +
  176 + NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStatePaused");
  177 + break;
  178 + case MPMoviePlaybackStateInterrupted:
  179 +
  180 + NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateInterrupted");
  181 + break;
  182 + case MPMoviePlaybackStateSeekingForward:
  183 +
  184 + NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateSeekingForward");
  185 + break;
  186 + case MPMoviePlaybackStateSeekingBackward:
  187 +
  188 + NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateSeekingBackward");
  189 + break;
  190 + default:
  191 +
  192 + NSLog(@"moviePlayBackStateDidChange : %ld", (long)_player.playbackState);
  193 + break;
  194 + }
  195 + }
  196 +}
  197 +
  198 +
  199 +
  200 +// 获取主播状态通知
  201 +- (void)anchorStatusChanged:(NSNotification *)notification
  202 +{
  203 + if (_player.anchorStatus == 2) { // 已结束
  204 +
  205 + }
  206 +// _bgView.anchorStatus = _player.anchorStatus;
  207 +}
  208 +
  209 +//重新连接获取主播状态
  210 +- (void)anchorStatusConnectFailed
  211 +{
  212 +
  213 +}
  214 +
  215 +#pragma mark - 移除通知 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  216 +- (void)removeMovieNotificationObservers
  217 +{
  218 + [[NSNotificationCenter defaultCenter]removeObserver:self
  219 + name:MPMoviePlayerLoadStateDidChangeNotification
  220 + object:nil];
  221 + [[NSNotificationCenter defaultCenter]removeObserver:self
  222 + name:MPMoviePlayerPlaybackDidFinishNotification
  223 + object:nil];
  224 + [[NSNotificationCenter defaultCenter]removeObserver:self
  225 + name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
  226 + object:nil];
  227 + [[NSNotificationCenter defaultCenter]removeObserver:self
  228 + name:MPMoviePlayerPlaybackStateDidChangeNotification
  229 + object:nil];
  230 +
  231 + [[NSNotificationCenter defaultCenter]removeObserver:self
  232 + name:CNLiveAnchorStatusChangedNotification
  233 + object:nil];
  234 +}
  235 +
32 @end 236 @end