iOS 調用音樂播放以及視頻播放器

來源:互聯網
上載者:User

標籤:音樂   loop   rgb   margin   back   pat   family   with   注意   

音樂播放

NSString *path = [[NSBundlemainBundle] pathForResource:@"預謀"ofType:@"mp3"];

    if (path) {

        NSURL *url = [NSURLfileURLWithPath:path];

        player= [[AVAudioPlayeralloc]initWithContentsOfURL:urlerror:nil];

        [playersetDelegate:self];

        player.volume =1;

        player.pan =1;

        player.numberOfLoops = -1;

        if ([playerprepareToPlay]) {

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

            [playerplay];

        } else {

           NSLog(@"no prepareToPlay");

        }

        //[player release];

    }

一定要注意player的引用,假設直接在函數內部申請一個暫時變數。那麼這個player會在函數運行完畢,運行release 會被釋放掉,假設須要在函數內部使用。那麼請sleep下。只是這樣會阻塞主線程的運作

視頻播放器

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

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

    [selfpresentMoviePlayerViewControllerAnimated:player];


iOS 調用音樂播放以及視頻播放器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.