1

私はこれのほとんどを機能させましたが、単純かもしれない何かに行き詰まっています。SpriteKit のカメラ ロールからビデオを再生しようとしています。ビデオはメイン バンドルから再生され、ビデオを選択するまでビデオ ピッカーも機能します。ビデオを選択するとピッカーがフリーズするため、メインスレッドをロックしていると思います。大変お世話になりました。

.h

#import <SpriteKit/SpriteKit.h>
#import "GameViewController.h"
#import <MobileCoreServices/UTCoreTypes.h>
@interface GameScene :     SKScene<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@end

.m

#import "GameScene.h"
#import <AVFoundation/AVFoundation.h>
@implementation GameScene {
AVPlayer *player;
SKVideoNode *videoNode1;
NSURL *fileURL;
NSString *moviePath;
UIViewController *viewController;
}

-(void)didMoveToView:(SKView *)view {
player = [AVPlayer playerWithURL: fileURL];

videoNode1 = [[SKVideoNode alloc] initWithAVPlayer:player];
videoNode1.size = CGSizeMake(self.frame.size.width,self.frame.size.height);
videoNode1.position = CGPointMake(self.frame.size.width/2.0f,self.frame.size.height/2.0f);
videoNode1.zPosition = 100.0f;
[self addChild:videoNode1];

player.volume = 1.0f;
[videoNode1 play];
}

- (void)getVideo {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =     UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,      nil];

viewController = self.view.window.rootViewController;
[viewController presentViewController: imagePicker animated: YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {

    fileURL = (NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
    moviePath = [fileURL path];

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
    UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);   
}
   player = [AVPlayer playerWithURL: fileURL];
}
viewController = self.view.window.rootViewController;
[viewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"place video");
 }
4

1 に答える 1

0

この機能を必要とする他の人のために、私自身の質問に答えます。imagePicker メソッドでノードとプレーヤーを設定する必要があります。

- (void)getVideo {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
viewController = self.view.window.rootViewController;
[viewController presentViewController: imagePicker animated: YES completion:nil];

}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

fileURL = [info objectForKey:UIImagePickerControllerMediaURL];
[picker dismissViewControllerAnimated:YES completion:NULL];
player = [AVPlayer playerWithURL: fileURL];

videoNode1 = [[SKVideoNode alloc] initWithAVPlayer:player];
videoNode1.size = CGSizeMake(self.frame.size.width, self.frame.size.height);
videoNode1.position = CGPointMake(self.frame.size.width/2.0f, self.frame.size.height/2);
videoNode1.zPosition = 100.0f;
[self addChild:videoNode1];

player.volume = 1.0f;
[videoNode1 play];

 }
于 2016-02-23T23:01:26.593 に答える