I am getting video data from server. i am using signalR Framework. first of all i am capturing video from iPhone photo library. Then next i am converting encoding format (base64EncodedStringwithOptions
) method. next i am sending video encrypted data to signalR server. and next i am receiving video data and decrypted and play the video data using AVPlayer
. but my problem video does not played. but i received video data from signalR. For decrypting i am using this method. (NSDataBase64DecodingIgnoreUnknownCharacters
)
我从服务器获取视频数据。我正在使用signalR Framework。首先,我正在从iPhone照片库中捕获视频。接下来我将转换编码格式(base64EncodedStringwithOptions)方法。接下来我将视频加密数据发送到signalR服务器。接下来我正在接收视频数据并解密并使用AVPlayer播放视频数据。但我的问题视频没有播放。但是我收到了来自signalR的视频数据。对于解密我正在使用这种方法。 (NSDataBase64DecodingIgnoreUnknownCharacters)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *videoFile=[documentDirectory stringByAppendingPathComponent:post.mediaName];
NSURL *url;
if ([[NSFileManager defaultManager] fileExistsAtPath:videoFile]) {
url=[NSURL URLWithString:videoFile];
}
NSLog(@"Video URL is:%@",url);
AVPlayer *player = [AVPlayer playerWithURL:url];
cell.videoPlayerController.player = player;
[player play];
i got Video URL like this:
我有这样的视频网址:
Video URL is:/Users/Library/Developer/CoreSimulator/Devices/EEC96DE7-6D0F-4D80-82B8-3C24E4F6B3EF/data/Containers/Data/Applicatication video0006.mp4
1 个解决方案
#1
1
You can use MPMoviePlayerController
to play video from url' but make sure that you have to declare property for that like,
您可以使用MPMoviePlayerController播放来自网址的视频,但请确保您必须为此声明属性,
@property MPMoviePlayerController *videoController;
don't create local object of MPMoviePlayerController
.
不要创建MPMoviePlayerController的本地对象。
you can use it something like,
你可以使用它,像
self.videoController = [[MPMoviePlayerController alloc] init];
[self.videoController setContentURL:tempView.videoURL]; //here your url
[self.videoController.view setFrame:CGRectMake (0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.videoController.view];
// close or cancel button if you want to put
UIButton *closeButton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-60, 20, 60, 30)];
[closeButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
[closeButton setTitle:@"Cancel" forState:UIControlStateNormal];
[self.videoController.view addSubview:closeButton];
// add observer to notify when playing will be completed if you want to put
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoPlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.videoController];
[self.videoController play];
Update :
You must use file url like,
你必须使用文件网址,
NSURL *url = [NSURL fileURLWithPath:videoFile];
instead of
[NSURL URLWithString:videoFile];
#1
1
You can use MPMoviePlayerController
to play video from url' but make sure that you have to declare property for that like,
您可以使用MPMoviePlayerController播放来自网址的视频,但请确保您必须为此声明属性,
@property MPMoviePlayerController *videoController;
don't create local object of MPMoviePlayerController
.
不要创建MPMoviePlayerController的本地对象。
you can use it something like,
你可以使用它,像
self.videoController = [[MPMoviePlayerController alloc] init];
[self.videoController setContentURL:tempView.videoURL]; //here your url
[self.videoController.view setFrame:CGRectMake (0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.videoController.view];
// close or cancel button if you want to put
UIButton *closeButton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-60, 20, 60, 30)];
[closeButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
[closeButton setTitle:@"Cancel" forState:UIControlStateNormal];
[self.videoController.view addSubview:closeButton];
// add observer to notify when playing will be completed if you want to put
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoPlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.videoController];
[self.videoController play];
Update :
You must use file url like,
你必须使用文件网址,
NSURL *url = [NSURL fileURLWithPath:videoFile];
instead of
[NSURL URLWithString:videoFile];