gpt4 book ai didi

ios - 在 iOS 中播放视频

转载 作者:行者123 更新时间:2023-12-01 17:20:08 24 4
gpt4 key购买 nike

我正在尝试播放存储在我设备上的视频,同时尝试使用 AVPlayerMPMoviePlayerController。视频 URL 为:file:///var/mobile/Containers/Data/Application/73695F3E-9351-447B-BB8A-0B4A62CE430F/Documents/08-03-201711:48:50.3gp。现在的问题是我出现黑屏。

AVPlayer *player = [AVPlayer playerWithURL:fileURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
[player pause];
[player play];
playerViewController.player = player;

[self addChildViewController: playerViewController];
[self.view addSubview: playerViewController.view];
//[playerViewController.player play];//Used to Play On start
[self presentViewController:playerViewController animated:YES completion:nil];

我认为问题出在链接上。我正在做的是获取本地目录链接并在该链接后附加名称。

最佳答案

我会给你一个好的解决方案。它完美地工作。

ViewController.h

#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) AVPlayerViewController *playerViewController;
- (IBAction)actionPlayVideo:(id)sender;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController (){
NSURL *vedioURL;
}

@end

@implementation ViewController
@synthesize playerViewController;

- (IBAction)actionPlayVideo:(id)sender{
NSString *fullpath = [[self documentsDirectory] stringByAppendingPathComponent:@"yourdate.3gp"];
vedioURL =[NSURL fileURLWithPath:fullpath];
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:vedioURL];
AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = playVideo;
playerViewController.player.volume = 0;
playerViewController.view.frame = self.view.bounds;
[self.view addSubview:playerViewController.view];
[playVideo play];
}
-(NSString *)documentsDirectory{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}

关于ios - 在 iOS 中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42129915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com