zoukankan      html  css  js  c++  java
  • 视频封转类

    //

    //  MediaViewController.m

    //  左右健康

    //

    //  Created by on 12-8-25.

    //

    //

    #import "MediaViewController.h"

    @interfaceMediaViewController (){

        UIImageView *backImageView;

    }

    @end

    @implementation MediaViewController

    @synthesize moviePlayer=_moviePlayer;

    @synthesize file_name;

    @synthesize movieControlStyle;

    @synthesize showNums = _showNums ;

    @synthesize stype;

    @synthesize isNeedStopMusic;

    -(id)init

    {

        if(self=[superinit])

        {

            stype=MPMovieControlStyleFullscreen;

            isNeedStopMusic=YES;

        }

        returnself;

    }

    - (void)viewDidLoad

    {

        [superviewDidLoad];

    // Do any additional setup after loading the view.

        [self.view setFrame:CGRectMake(0, 0, 1024, 768)];

    //    self.view.backgroundColor=[UIColor redColor];

        if (file_name == nil) {

            file_name = @"LOGO";

        }

        if(isNeedStopMusic)

            [[NSNotificationCenterdefaultCenter] postNotificationName:@"StopBackGroundMusic"object:nil];

    //    NSString *loc_Path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@.mp4",file_name] ofType:nil inDirectory:RESOURCES_PATH];

    //    

    //    if (!loc_Path) {

    //        [self performSelector:@selector(moviePlayBackDidFinish:) withObject:nil afterDelay:0.8];

    //        return;

    //    }

    //    [self playLocalVideo:loc_Path];

        

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleReturnBackGround) name:@"applicationDidBecomeActive_SS" object:nil];

        

        backImageView = [[UIImageViewalloc]initWithFrame:CurrentDeviceBounds];

        backImageView.userInteractionEnabled = YES;

        backImageView.tag = 1 ;

        [self.viewaddSubview:backImageView];

        [selfplayLocalVideo];

    //    [self performSelector:@selector(playLocalVideo) withObject:nil afterDelay:0.1];

    }

    - (void)handleReturnBackGround{

        NSLog(@"handleReturnBackGround");

        if( _moviePlayer ){

            [_moviePlayer play];

        }

    }

    -(void)playLocalVideo

    {

        NSString *loc_Path = [[NSBundlemainBundle] pathForResource:[NSStringstringWithFormat:@"%@.mp4",file_name] ofType:nilinDirectory:RESOURCES_PATH];

        

        if (!loc_Path) {

            [self performSelector:@selector(moviePlayBackDidFinish:) withObject:nil afterDelay:0.8];

            return;

        }

        

    //    NSLog(@"播放本地视频:%@",_path);

        //加载视频

    //    MPMoviePlayerController *mp;

        //播放的路径

        NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:loc_Path];

        _moviePlayer = [[MPMoviePlayerControlleralloc] initWithContentURL:fileURL];

        //设置大小

        CGRect frame;

        frame=CGRectMake(0, 0, 1024, 768);

        _moviePlayer.view.frame = frame;

    //    self.view.frame = frame;

        //把加载到的视频传递到页面播放器上

    //    self.moviePlayer = mp;

    //[mp release];

        //设置大小

        //    [moviePlayer.view setFrame:self.view.bounds];

    //    _moviePlayer.shouldAutoplay = YES;

        

        _moviePlayer.controlStyle = stype;// movieControlStyle;

        _moviePlayer.fullscreenYES;

        _moviePlayer.scalingMode = MPMovieScalingModeFill;

        [backImageViewinsertSubview:_moviePlayer.viewatIndex:0];

        

        if( _showNums == StartMovieControl){

    //        _moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

            _moviePlayer.fullscreenYES;

            _moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

            _moviePlayer.repeatMode = MPMovieRepeatModeOne ;

        }

        

        [_moviePlayerplay];

    //    CGAffineTransform landscapeTransform;

    //landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));//控制视频画面的朝向,也就是旋转角度

    //landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);

    //[self.moviePlayer.view setTransform: landscapeTransform];

    //    //加载条

    //    [self ForLoading];

        //    activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

        //    activityView.frame = CGRectMake((self.view.frame.size.width-37.0)/2, (self.view.frame.size.height-37.0)/2, 37.0f, 37.0f);

        //    [self.view addSubview:activityView];

        //    [activityView startAnimating];

        //完成播放消息

        [[NSNotificationCenterdefaultCenter] addObserver:self

                                                 selector:@selector(moviePlayBackDidFinish:)

                                                     name:MPMoviePlayerPlaybackDidFinishNotification

                                                   object:nil];

        [[NSNotificationCenterdefaultCenter] addObserver:self

                                                 selector:@selector(moviePlayBackDidChange:)

                                                     name:MPMoviePlayerPlaybackStateDidChangeNotification

                                                   object:nil];

    //    //加载完成

    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieStartCallback:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

    //    [self performSelector:@selector(startShow) withObject:_path afterDelay:0.1];

        

    //    if (self.movieControlStyle != MPMovieControlStyleFullscreen) {

    //        UIButton *loc_btn = [[UIButton alloc] initWithFrame:CGRectMake(900, 700, 100, 40)];

    ////        loc_btn.backgroundColor = [UIColor redColor];

    //        [loc_btn setTitle:@" " forState:UIControlStateNormal];

    //        [loc_btn addTarget:self action:@selector(stopMediaEvent) forControlEvents:UIControlEventTouchUpInside];

    //        [self.view addSubview:loc_btn];

    //    }

        

    //    [self addBackButtonInView:self.view];

    }

    -(void)stopMediaEvent{

        [selfmoviePlayBackDidFinish:nil];

    }

    - (void) moviePlayBackDidChange:(NSNotification*)notification

    {

        NSLog(@"hejiang:%@-----%d",[notification userInfo],self.moviePlayer.playbackState);//MPMoviePlaybackState

        if (MPMoviePlaybackStateInterrupted == _moviePlayer.playbackState) {

            [_moviePlayer play];

        }

    }

    - (void) moviePlayBackDidFinish:(NSNotification*)notification

    {

        NSLog(@"=====播放结束=====");

    //    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

        [selfhiddenOrNoStausBar:YES];

        

        [[NSNotificationCenterdefaultCenter] removeObserver:self];

        [[NSNotificationCenterdefaultCenter] postNotificationName:@"StartBackGroundMusic"object:nil];

        [selfbackButtonAction:nil];

        

        return;

        

        

        if (self.movieControlStyle == MPMovieControlStyleFullscreen) {

            [selfdismissModalViewControllerAnimated:YES];

            [_moviePlayer stop];

            [_moviePlayer.viewremoveFromSuperview];

            _moviePlayer=nil;

            [self.viewremoveFromSuperview];

        }else{

            [_moviePlayer stop];

            [_moviePlayer.viewremoveFromSuperview];

            _moviePlayer=nil;

            [self.viewremoveFromSuperview];

        }

        

        [[NSNotificationCenterdefaultCenter] postNotificationName:@"StartBackGroundMusic"object:nil];

        

        return;

        

        NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

        switch ([reason intValue])

        {

            caseMPMovieFinishReasonPlaybackEnded:

            {

                NSLog(@"playbackFinished. Reason: Playback Ended");

                

    //            [self performSelector:@selector(stopPlay) withObject:nil afterDelay:0.1];

            }

                break;

            caseMPMovieFinishReasonPlaybackError:

            {

                NSLog(@"playbackFinished. Reason: Playback Error");

                //回到之前的导航界面

                //            [self.navigationController popViewControllerAnimated:YES];

    //            [self performSelector:@selector(backEvent) withObject:nil afterDelay:0.3];

                //            [self backEvent];

            }

                break;

            caseMPMovieFinishReasonUserExited:

            {

                NSLog(@"playbackFinished. Reason: User Exited");

                //回到之前的导航界面

                //            [self.navigationController popViewControllerAnimated:YES];

    //            [self performSelector:@selector(stopPlay) withObject:nil afterDelay:0.1];

            }

                break;

            default:

                break;

        }

        

    }

    - (void)viewDidUnload

    {

        [superviewDidUnload];

        // Release any retained subviews of the main view.

    }

    -(void)dealloc{

        NSLog(@"-------1231231231231");

        [[NSNotificationCenterdefaultCenter] removeObserver:self];

    }

    @end

    //

    //  MediaViewController.h

    //  左右健康

    //

    //  Created by on 12-8-25.

    //

    //

    #import <UIKit/UIKit.h>

    #import <MediaPlayer/MediaPlayer.h>

    #import "BuildingShowbaseViewController.h"

    typedefenum{

        GMZearo,

        StartMovieControl,

        

    }ControlMoviePlayerMode;

    @interface MediaViewController : BuildingShowbaseViewController {

        NSString *file_name;

    }

    @property (nonatomic,strong) NSString *file_name;

    @property (nonatomic,strong) MPMoviePlayerController *moviePlayer;

    @property (nonatomic,assign) MPMovieControlStyle movieControlStyle;

    @property (nonatomic , assign) int showNums;

    @property(nonatomic,assign)MPMovieControlStyle stype;

    @property(nonatomic,assign)BOOL isNeedStopMusic;

    @end

  • 相关阅读:
    HttpServletResponse工具类和HttpServletRequest工具类,前台参数接收方式和后台返回(JSON)数据格式
    centos7使用docker安装es(elasticsearch)
    springboot发送邮件
    Springboot在工具类(Util)中使用@Autowired注入Service
    Spring Boot应用程序启动器
    ssh端口转发功能
    小型自动化运维工具pssh和传输工具rsync
    用linux主机做网关搞源地址转换(snat)
    shell脚本判断里面的字符含义
    heartbeat高可用
  • 原文地址:https://www.cnblogs.com/alihaiseyao/p/3603808.html
Copyright © 2011-2022 走看看