zoukankan      html  css  js  c++  java
  • iOS 调用音乐播放以及视频播放器

    音乐播放

    NSString *path = [[NSBundle mainBundle] pathForResource:@"预谋" ofType:@"mp3"];

        if (path) {

            NSURL *url = [NSURL fileURLWithPath:path];

            player= [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];

            [player setDelegate:self];

            player.volume = 1;

            player.pan = 1;

            player.numberOfLoops = -1;

            if ([player prepareToPlay]) {

                NSLog(@"prepareToPlay:%@",path);

                [player play];

            } else {

                NSLog(@"no prepareToPlay");

            }

            //[player release];

        }

    一定要注意player的引用,假设直接在函数内部申请一个暂时变量。那么这个player会在函数运行完毕,运行release 会被释放掉,假设须要在函数内部使用。那么请sleep下。只是这样会阻塞主线程的运作

    视频播放器

    NSURL * movieurl = [NSURL URLWithString:@"http://v.youku.com/player/getRealM3U8/vid/XNDUwNjc4MzA4/type/video.m3u8"];

        MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieurl];

        [self presentMoviePlayerViewControllerAnimated:player];


  • 相关阅读:
    nginx配置详解
    nginx源码安装
    nginx调优
    生产环境常见的HTTP状态码列表
    如何修复损坏的MySQL数据表
    navicat报caching_sha2_password异常
    angular下载安装
    nodejs前端开发环境安装
    eclipse自动生成变量名声明(按方法返回值为本地变量赋值)
    eclipse设置代码模板和格式
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6784912.html
Copyright © 2011-2022 走看看