在屏幕触摸时关闭 MPMoviePlayerController

发布于 2024-11-05 23:26:39 字数 323 浏览 2 评论 0原文


我遵循了这个 教程,并在我的应用程序中包含一个视频播放器。
但问题是我想隐藏控件,并能够在屏幕触摸上关闭视频。
我尝试在视频前面放置一个大的透明按钮来触发关闭功能,但没有成功。视频将始终位于按钮上方,并且永远不会调用该函数。
还有其他方法吗?

I followed this tutorial, and included a video player in my app.
But the problem is that i want to hide the controls, and be able to dismiss the video on screen touch.
I tried putting a big transparent button in front of the video that triggers the dismiss function, but with no luck. the video will always be over the button and the function will never be called.
Is there another way of doing it?
ty

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

紧拥背影 2024-11-12 23:26:39

**嗨,我认为 AVPlayer 变得更适合你,你可以按如下方式使用它,然后如果你想播放则添加子视图,如果你想停止从超级视图中删除它

** #import"AVFoundation/AVFoundation.h"

**用于创建玩家列表:

NSString *path1 = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]]; 
player= [AVPlayer playerWithPlayerItem:first];
[self.playerView setPlayer:player];
[player play];

** 您必须在其中为玩家视图创建 uiview :

(id)initWithFrame:(CGRect)frame {self = [super initWithFrame:frame];
if (self) {
    // Initialization code.
}
return self;
}
+ (Class)layerClass {
 return [AVPlayerLayer class];
}

-(AVPlayer*)player {
 return [(AVPlayerLayer *)[self layer] player];
}

-(void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];   
}

**Hi I think AVPlayer is become more suitable to you,You can use it as below and then add subview if you want to play and if you want to stop remove it from super view

** #import"AVFoundation/AVFoundation.h"

**For creating Player List:

NSString *path1 = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]]; 
player= [AVPlayer playerWithPlayerItem:first];
[self.playerView setPlayer:player];
[player play];

** You have to make uiview for playerview in it :

(id)initWithFrame:(CGRect)frame {self = [super initWithFrame:frame];
if (self) {
    // Initialization code.
}
return self;
}
+ (Class)layerClass {
 return [AVPlayerLayer class];
}

-(AVPlayer*)player {
 return [(AVPlayerLayer *)[self layer] player];
}

-(void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];   
}
黎歌 2024-11-12 23:26:39

PlayerViewControll .H

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface PlayerView : UIView UILabel *pageNumberLabel;
int pageNumber;
}
@property (nonatomic, retain) AVPlayer *player;
- (id)initWithPageNumber:(int)page;

PlayerView.M

#import "PlayerView.h"


@implementation PlayerView
 - (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {}
return self;
}
 + (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}

MainViewControll .H

#import <AVFoundation/AVFoundation.h>
#import "PlayerView.h"
@interface MainViewController : UIViewController {
IBOutlet PlayerView *playerView;
NSString *url;
AVPlayer *player;
NSMutableArray *arrIteam;
}
@property(nonatomic,retain) NSMutableArray *arrIteam;
@property (nonatomic, retain) AVPlayer *player;
@property(nonatomic ,retain)IBOutlet PlayerView *playerView;

PlayerView.M

#import "MainViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation MainViewController
@synthesize player,playerView,arrIteam;
- (void)viewDidLoad {
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]]; 
arrIteam = [[NSMutableArray alloc] initWithObjects:first,second, third,fourth,nil]; 
player=[AVPlayer playerWithPlayerItem:[arrIteam objectAtIndex:i]];
[self.playerView setPlayer:player];
[player play];
[super viewDidLoad];
}

PlayerViewControll .H

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface PlayerView : UIView UILabel *pageNumberLabel;
int pageNumber;
}
@property (nonatomic, retain) AVPlayer *player;
- (id)initWithPageNumber:(int)page;

PlayerView .M

#import "PlayerView.h"


@implementation PlayerView
 - (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {}
return self;
}
 + (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}

MainViewControll .H

#import <AVFoundation/AVFoundation.h>
#import "PlayerView.h"
@interface MainViewController : UIViewController {
IBOutlet PlayerView *playerView;
NSString *url;
AVPlayer *player;
NSMutableArray *arrIteam;
}
@property(nonatomic,retain) NSMutableArray *arrIteam;
@property (nonatomic, retain) AVPlayer *player;
@property(nonatomic ,retain)IBOutlet PlayerView *playerView;

PlayerView.M

#import "MainViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation MainViewController
@synthesize player,playerView,arrIteam;
- (void)viewDidLoad {
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]]; 
arrIteam = [[NSMutableArray alloc] initWithObjects:first,second, third,fourth,nil]; 
player=[AVPlayer playerWithPlayerItem:[arrIteam objectAtIndex:i]];
[self.playerView setPlayer:player];
[player play];
[super viewDidLoad];
}
别在捏我脸啦 2024-11-12 23:26:39

您应该使用 UIGestureRecognizer 类。有关详细信息,请参阅手册。或者阅读本教程

You should use UIGestureRecognizer class. See manual for details. Or read this tutorial.

∞觅青森が 2024-11-12 23:26:39

使用此代码。

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopPlayer)];


[self.view addGestureRecognizer:gestureRecognizer];
gestureRecognizer.cancelsTouchesInView = NO;
[gestureRecognizer release];

查看确实加载;

- (void) stopPlayer

停止玩家并从视图中释放该玩家。

希望对您有帮助。

Use this code.

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopPlayer)];


[self.view addGestureRecognizer:gestureRecognizer];
gestureRecognizer.cancelsTouchesInView = NO;
[gestureRecognizer release];

in view didload;

And in

- (void) stopPlayer

stop the player and release this player from view.

Hope it helps you.

浅语花开 2024-11-12 23:26:39

我刚刚找到

i just found the solution to my problem in another question asked here.
after some minor modifications, the code worked as expected. thank you all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文