2015年2月11日 星期三

支援眾多video與audio格式的MobileVLCKit

支援格式

支援的video格式https://www.videolan.org/vlc/features.php?cat=video
支援的audio格式https://www.videolan.org/vlc/features.php?cat=audio

安裝方式

By CocoaPods

pod 'MobileVLCKit'

從night build下載
http://nightlies.videolan.org/build/ios/

Build source code,使用-f參數build出包含所有arch的framework

./buildMobileVLCKit.sh -f

https://wiki.videolan.org/VLCKit/#Building_the_framework_for_iOS

Sample Code

參考範例DropIn-Player http://cl.ly/0G2Y2M1R1X3U

初始化

記得引用MobileVLCKit的原始檔要從.m改為.mm,這樣編譯才不會出錯。

// Set up a videoView by hand. You can also do that in the nib file
   videoView = [[VLCVideoView alloc] initWithFrame:[[window contentView] bounds]];
   [[window contentView] addSubview:videoView];
   [videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];

   // Init the player object
   player = [[VLCMediaPlayer alloc] initWithVideoView:videoView];
   VLCMedia *media = [VLCMedia mediaWithPath:@"/to/my/movie"];
   //設置delegate等一下可以知道歌曲有多長
   media.delegate = self;
   [player setMedia:media];
   [player play];

控制播放進度(progress)

progressValue為UISlider傳過來的值

- (void)seek:(float) progressValue
{
    [self.mediaPlayer setPosition:progressValue];
}

顯示目前播放進度

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaPlayerTimeChanged:) name:VLCMediaPlayerTimeChanged object:nil];
- (void)mediaPlayerTimeChanged:(NSNotification *)aNotification
{
    self.playbackTime = [_player.time stringValue];
}

獲取duration

如果有把player裡面的VLCMedia設置delegate的話,就會收到通知

- (void)mediaDidFinishParsing:(VLCMedia *)aMedia
{
    //更新duration
}

監控狀態

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaPlayerStateChanged:) name:VLCMediaPlayerStateChanged object:nil];
- (void)mediaPlayerStateChanged:(NSNotification *)aNotification
{
    VLCMediaPlayerState state;
    switch (state) {
        case VLCMediaPlayerStatePaused:
            break;

        case VLCMediaPlayerStateStopped:
            break;

        case VLCMediaPlayerStateBuffering:
            break;

        case VLCMediaPlayerStatePlaying:
            break;

        case VLCMediaPlayerStateEnded:
            break;

        case VLCMediaPlayerStateError:
            break;

        default:
            break;
    }
}

沒有留言:

張貼留言