Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正改善 #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Example/KRVideoPlayer/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "FirstViewController.h"
#import "KRVideoPlayerController.h"

@interface FirstViewController ()
@interface FirstViewController () <KRViedoPlayerDelegate>

@property (nonatomic, strong) KRVideoPlayerController *videoController;

Expand Down Expand Up @@ -46,6 +46,7 @@ - (void)playVideoWithURL:(NSURL *)url
if (!self.videoController) {
CGFloat width = [UIScreen mainScreen].bounds.size.width;
self.videoController = [[KRVideoPlayerController alloc] initWithFrame:CGRectMake(0, 0, width, width*(9.0/16.0))];
self.videoController._delegate = self;
__weak typeof(self)weakSelf = self;
[self.videoController setDimissCompleteBlock:^{
weakSelf.videoController = nil;
Expand All @@ -55,4 +56,8 @@ - (void)playVideoWithURL:(NSURL *)url
self.videoController.contentURL = url;
}

- (void)videoPlaybackEnded
{
NSLog(@"Video Playing Completed");
}
@end
5 changes: 5 additions & 0 deletions Example/KRVideoPlayer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
5 changes: 5 additions & 0 deletions Pod/Classes/KRVideoPlayerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

@import MediaPlayer;

@protocol KRViedoPlayerDelegate
- (void)videoPlaybackEnded;
@end

@interface KRVideoPlayerController : MPMoviePlayerController

@property (assign, nonatomic) id _delegate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为了全局命名规范,修改为@Property (weak, nonatomic) id delegate;

关键点,1.weak, 2.id, 3.delegate

@property (nonatomic, copy)void(^dimissCompleteBlock)(void);
@property (nonatomic, assign) CGRect frame;

Expand Down
11 changes: 9 additions & 2 deletions Pod/Classes/KRVideoPlayerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ - (instancetype)initWithFrame:(CGRect)frame
self.videoControl.frame = self.view.bounds;
[self configObserver];
[self configControlAction];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放入configObserver里

}
return self;
}
Expand Down Expand Up @@ -161,7 +162,7 @@ - (void)pauseButtonClick
{
[self pause];
self.videoControl.playButton.hidden = NO;
self.videoControl.pauseButton.hidden = YES;
self.videoControl.pauseButton.hidden = YES;
}

- (void)closeButtonClick
Expand Down Expand Up @@ -206,7 +207,7 @@ - (void)shrinkScreenButtonClick
- (void)setProgressSliderMaxMinValues {
CGFloat duration = self.duration;
self.videoControl.progressSlider.minimumValue = 0.f;
self.videoControl.progressSlider.maximumValue = duration;
self.videoControl.progressSlider.maximumValue = floor(duration);
}

- (void)progressSliderTouchBegan:(UISlider *)slider {
Expand Down Expand Up @@ -290,5 +291,11 @@ - (void)setFrame:(CGRect)frame
[self.videoControl layoutIfNeeded];
}

#pragma mark - Delegate

-(void)moviePlaybackDidFinish{
if ([self._delegate respondsToSelector:@selector(videoPlaybackEnded)]){
[self._delegate videoPlaybackEnded];
}
}
@end