zoukankan      html  css  js  c++  java
  • AVAudioPlayer ,MPMoviePlayerController,简单使用

    1、音频播放,

    需要引入系统库文件AVFoundation.framework,并加上头文件:

    #import <AVFoundation/AVFoundation.h>

    - (void)readPoemVoiceAtIndex:(NSInteger )index

    {

        NSString *poemVoice = [_poemVoiceArray objectAtIndex:index];

        //    NSLog(@"%@",read);

        NSString *path = [[NSBundle mainBundle]pathForResource:poemVoice ofType:@"wav"];

        if (!path) {  return;    }//AVAudioPlayer的初始化任务可以放到一个一步线程中,这样有益于用户体验。

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            NSURL *url = [NSURL fileURLWithPath:path];

            NSError *error;

            self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

            [_player prepareToPlay];

            dispatch_async(dispatch_get_main_queue(), ^{

                self.player.volume =0.5;// _poemSet.volume;

               [_player play];

            });

        });

    }

    1、视频播放,

    进行视频操作需要引入库MediaPlayer.framework,并加入头文件:

    #import <MediaPlayer/MediaPlayer.h>

    -(void)moveStep1

    {

    #pragma mark - make appStar animation

        /*添加视屏播放开启界面,使用到通知中心的方法,用于监听视频播放完毕*/

        //    NSString *url=[[NSBundle mainBundle]pathForResource:@"Comp 9" ofType:@"mov"];

        NSString *url=[[NSBundle mainBundle]pathForResource:@"mov_bbb" ofType:@"mp4"];

        _player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:url]];

        _player.view.transform = CGAffineTransformMakeRotation(1.57);

        [[NSNotificationCenter defaultCenter]

         addObserver:self

         selector:@selector(beginView) name:MPMoviePlayerPlaybackDidFinishNotification object:_player];

        _player.scalingMode=MPMovieScalingModeAspectFill;  

      _player.controlStyle=MPMovieControlStyleNone;

      _player.view.frame=CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen]   bounds].size.height);

      [_player setFullscreen:YES animated:YES];

      [self.window addSubview:_player.view];

      [_player play];

    }

    -(void)beginView

    {    [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:_player];

        [_player.view removeFromSuperview];  

    //    self.window.rootViewController = xueIntbc;

    }

     

     

  • 相关阅读:
    Android 获取SDCard中某个目录下图片
    Android ListView中 每一项都有不同的布局
    Listview 异步加载图片之优化篇(有图有码有解释)
    Android 实现ListView异步加载图片
    android ListView异步加载图片(双缓存)
    使用 COM 风格的编程接口
    deb包+软件图标+添加到系统菜单+举例安装卸载
    罗将公布手机锤,我感到深深的内疚
    【 D3.js 入门系列 --- 9.6 】 生产的包图
    Junit指定测试运行顺序
  • 原文地址:https://www.cnblogs.com/longtaozi/p/3836512.html
Copyright © 2011-2022 走看看