你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS Dev (24) 最簡單的M3U8播放器

iOS Dev (24) 最簡單的M3U8播放器

編輯:IOS開發綜合

iOS Dev (24) 最簡單的M3U8播放器

  • 作者:CSDN 大銳哥
  • 地址:http://blog.csdn.net/prevention

    概述

    用 MediaPlayer Framework 中的 MPMoviePlayerController 構造一個最簡單的 M3U8 播放器。

    Show Me the Codes

    創建一個空項目,然後改寫 AppDelegate:

    AppDelegate.h

    #import 
    
    @class PlayerViewController;
    
    @interface AppDelegate : UIResponder 
    
    @property (strong, nonatomic) UIWindow *window;
    @property (strong, nonatomic) PlayerViewController *vc;
    
    @end
    

    AppDelegate.m

    #import "AppDelegate.h"
    #import "PlayerViewController.h"
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary    *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.vc = [[PlayerViewController alloc] initWithNibName:nil bundle:nil];
        self.window.rootViewController = self.vc;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    ...
    
    @end
    

    其他默認函數我就略了。

    PlayerViewController.h

    #import 
    
    @interface PlayerViewController : UIViewController
    
    @end
    

    PlayerViewController.m

    在 viewDidLoad 中初始化 MPMoviePlayerController,並指定一個播放地址。這裡我寫死了地址,是為了演示。

    #import "PlayerViewController.h"
    #import 
    
    @interface PlayerViewController ()
    
    @property (strong, nonatomic) MPMoviePlayerController *streamPlayer;
    
    @end
    
    @implementation PlayerViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        NSURL *streamURL = [NSURL URLWithString:@"http://www.thumbafon.com/code_examples/video/segment_example/prog_index.m3u8"];
    
        self.streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
        [self.streamPlayer.view setFrame:self.view.bounds];
        self.streamPlayer.controlStyle = MPMovieControlStyleEmbedded;
    
        [self.view addSubview: self.streamPlayer.view];
        [self.streamPlayer play];
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    

    Run It !

    -

    轉載請注明來自:http://blog.csdn.net/prevention

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved