Custom MPMoviePlayerController (gesture control improves volume and progress)

Source: Internet
Author: User

Use System-Customized MPMoviePlayerController. Make gestures move up and down to raise (lower) volume, gestures to left and right to control fast forward and rewind

#import <MediaPlayer/MediaPlayer.h>

@interface kkbmovieplayercontroller:mpmovieplayercontroller< Uigesturerecognizerdelegate>

@end

#import "KKBMoviePlayerController.h" #import "AppDelegate.h" @interface Kkbmovieplayercontroller () {BOOL _infullscree
    N
    
    Uipangesturerecognizer *_pan;
    Cgpoint _lastpoint;
    BOOL _startchange;
BOOL _changevolume; @end @implementation Kkbmovieplayercontroller-(ID) Initwithcontenturl: (Nsurl *) url{self =[super initwithcontent
    Url:url];
        if (self) {self.view.backgroundColor = [uicolor Clearcolor];
        Self.initialplaybacktime =-1;
        Self.endplaybacktime =-1;
        [Self preparetoplay];
        
        [Self play]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector
                                                   (Enterfullscreen:) name:mpmovieplayerwillenterfullscreennotification
        
        Object:nil];
                             [[Nsnotificationcenter Defaultcenter] Addobserver:self                    Selector: @selector (leavefullscreen:) Name:mpmovie
    Playerwillexitfullscreennotification Object:nil];
return self; #pragma mark-full screen Controller-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer shouldreceive

Touch: (Uitouch *) touch{return YES;} -(void) Handlepan: (uipangesturerecognizer*) rec{if (_infullscreen) {if (rec.state = = Uigesturerecognizerstate
        began) {_lastpoint = [rec LocationInView:self.view];
            
            else if (rec.state = = uigesturerecognizerstatechanged) {cgpoint nowpoint = [rec LocationInView:self.view]; if (_startchange = NO) {if fabs (Nowpoint.y-_lastpoint.y) > Fabs (nowpoint.
                X-_lastpoint.x)) {_changevolume = NO;
                else {_changevolume = YES;
    }            _startchange = YES; else {if (_changevolume) {//change volume float volume = [[MPM
                    Usicplayercontroller Applicationmusicplayer] volume];
                    
                    float newvolume = volume; if (nowpoint.x = = _lastpoint.x) {} else {if (nowpoi
                        Nt.x < _lastpoint.x) {newvolume = 0.01;
                        else {newvolume = 0.01;  } if (Newvolume < 0) {Newvolume
                    = 0;
                    else if (Newvolume > 1.0) {newvolume = 1.0;
                [[Mpmusicplayercontroller Applicationmusicplayer] setvolume:newvolume];
            } else {        Change playback State if (self.playbackstate!= mpmovieplaybackstateseekingforward &&amp
                        ;
                            
                        Self.playbackstate!= Mpmovieplaybackstateseekingbackward) {if (Nowpoint.y = = _lastpoint.y) { 
                                else {if (Nowpoint.y < _lastpoint.y) {
                            [Self beginseekingforward];
                            else {[Self beginseekingbackward];
                    } _lastpoint = Nowpoint; else if (rec.state = Uigesturerecognizerstateca
                   ncelled | |
                   Rec.state = = Uigesturerecognizerstateended | |
            Rec.state = = uigesturerecognizerstatefailed) {_startchange = NO;
 [Self endseeking];       }}-(void) Enterfullscreen: (nsnotification*) notification{_infullscreen = YES;
    _pan = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (Handlepan:)];
    
    _pan.delegate = self;
[[[[[UIApplication sharedapplication] windows] objectatindex:0] addgesturerecognizer:_pan];
    }-(void) Leavefullscreen: (nsnotification*) notification{_infullscreen = NO;
[[[[[UIApplication sharedapplication] windows] objectatindex:0] removegesturerecognizer:_pan];
 } @end


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.