• 周四. 4 月 23rd, 2026

物嫩软件资讯网

软件资讯来物嫩

iOS在线播放--影音播放的两个方式

admin@wunen

4 月 26, 2025


#import

“ViewController.h”


#import

<MediaPlayer/MediaPlayer.h>


#import

<AVFoundation/AVFoundation.h>


@interface



ViewController

()

@property

(

strong

,

nonatomic

)


AVPlayer


*avPlayer;

@property

(

strong

,

nonatomic

)


MPMoviePlayerController


*mpPlayer;

@end


@implementation

ViewController

– (

void

)viewDidLoad {


[


super



viewDidLoad

];



// Do any additional setup after loading the view, typically from a nib.

}

– (

void

)didReceiveMemoryWarning {


[


super



didReceiveMemoryWarning

];



// Dispose of any resources that can be recreated.

}

– (

void

)touchesBegan:(

NSSet

*)touches withEvent:(

UIEvent

*)event

{



//192.168.0.125




NSURL


*url=[


NSURL




URLWithString


:

@”http://192.168.0.125:8080/WYServer/resources/htmls/Go.mp3″

];




NSURL


*urlMoive=[


NSURL




URLWithString


:

@”http://192.168.0.125:8080/WYServer/resources/videos/minion_01.mp4″

];

//    self.avPlayer = [[AVPlayer alloc] initWithURL:url];

//    [self.avPlayer play];



//——

方式

1-

-----

//    self.mpPlayer=[[MPMoviePlayerController alloc] initWithContentURL:urlMoive];

//    [self.view addSubview:self.mpPlayer.view];

//    [self.mpPlayer setFullscreen:YES];

//

//    [self.mpPlayer play];



//——

方式

2-

-----


[


self



presentMoviePlayerViewControllerAnimated

:[[


MPMoviePlayerViewController



alloc

]

initWithContentURL

:urlMoive]];

}

@end

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注