2012-05-27 31 views
2

我試圖添加一個子視圖一旦按鈕被點擊,然後把它放在前面,並添加一個AVPlayer實例播放電臺流。音頻正在播放,但AVPlayer不可見,我不知道如何使AVPlayer在子視圖中可見。我一直在尋找蘋果圖書館的例子和信息,但它很糟糕。AVPlayer工作,但在子視圖中不可見

這裏是調用方法:

- (IBAction)radioButton:(id)sender { 

    radioButton.selected=TRUE; 
    twitterButton.selected=FALSE; 

    [self.view bringSubviewToFront:radioView]; 
    radioView.hidden = FALSE; 

    NSURL *url = [NSURL URLWithString:@"http://streaming3.radiocat.net:80/"]; 
        // You may find a test stream at <http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8>. 
    self.playerItem = [AVPlayerItem playerItemWithURL:url]; 

    //[playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext]; 

    self.player = [AVPlayer playerWithPlayerItem:playerItem]; 
    [self.player play]; 
} 

非常感謝

+0

那麼接受答案中的代碼是什麼讓AVPlayer出現?我們遇到同樣的問題。 – Praxiteles

回答

2

AVPlayer沒有自己的用戶界面,你必須自己從UIKit類創建它,並從他們的操作連接相關IBAction爲消息控制AVPlayer實例的方法。

+0

非常感謝您的幫助。例如,你的意思是添加UIButton動作來播放方法和音量控制到UISlider? – theomen

+0

準確地說:對於播放,UIButton的操作方法觸發AVPlayer的播放和暫停方法;但是,音量工作方式不同,具體取決於您使用AVPlayer的方式 - 請參閱[MPVolumeView](http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html)開始。 – 2012-05-27 14:23:22

+0

非常感謝!!!!!! – theomen