I'm using MWPhotoBrowser in which photos and videos are shown in gridview as thumb. and shows full size image. It works fine for image view.
I have applied code for video play in
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
method to play video.In which MPMoviePlayerViewController is used to play video. It will play video directly when video image displays
I want to apply video play button to play video by user interaction. If there is any possible way to do that then please suggest. Thanks in advance.
This is not possible with the current available delegates methods, so I've made the one for my own use in my app, here you go.
Step 1:
Look for this file, MWPhotoBrowser.h
Under the delegate declarations, i.e. under this @protocol MWPhotoBrowserDelegate <NSObject>
add one more delegate, - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didSelectedPhotoAtIndex:(NSUInteger)selectedPhotoIndex;
I make it optional.
Also, declare this function too, - (void) singleTapOnCurrentPhoto;
Step 2:
Now open, MWPhotoBrowser.m
make a definition of, - (void) singleTapOnCurrentPhoto
like this,
- (void) singleTapOnCurrentPhoto {
if(self.delegate && [self.delegate respondsToSelector:@selector(photoBrowser:didSelectedPhotoAtIndex:)]) {
[self.delegate photoBrowser:self didSelectedPhotoAtIndex:self.currentIndex];
}
}
Step 3:
Now look for this file, MWZoomingScrollView.m
find this method, - (void)handleSingleTap:(CGPoint)touchPoint;
update it like this,
- (void)handleSingleTap:(CGPoint)touchPoint {
[_photoBrowser performSelector:@selector(singleTapOnCurrentPhoto)];
[_photoBrowser performSelector:@selector(toggleControls) withObject:nil afterDelay:0.2];
}
Step 4:
You're done! You can use it in your UIViewController
class like this,
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didSelectedPhotoAtIndex:(NSUInteger)selectedPhotoIndex {
NSLog(@"Photo tapped at index %lu",(unsigned long)selectedPhotoIndex);
}
Understanding of each steps:
In step:1 we're declaring our own delegate method to work with MWPhotoBrowser
, once we create we've to make use of it some where, so we've also declaring a method named singleTapOnCurrentPhoto
to call it with the object of photo browser.
In step:2 we've calling the delegate which we'll implement into our UIViewController
where we're showing MWPhotoBrowser
.
In step:3 we'll need to know, when current photo will be tap (this was done by Michael, thanks!). So we're calling the function singleTapOnCurrentPhoto
when user perform single tap on current photo. Here, we'll call the singleTapOnCurrentPhoto
using the object of _photoBrowser
of MWPhotoBrowser
In step:4 we're done! Now we can use that delegate. So we're implementing into class where we need it. That's all!