我有视频应用程序,我想从视频库浏览视频。任何人都可以帮我解决如何从iphone中的视频库浏览特定视频的问题。谢谢
答案 0 :(得分:3)
使用UIImagePickerController
:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [NSArray arrayWithObjects: (NSString *) kUTTypeMovie, nil];
picker.delegate = self; // don't forget implement UINavigationControllerDelegate, UIImagePickerControllerDelegate methods
[picker presentModalViewController: cameraUI animated: YES];
阅读Camera Programming Topics了解更多详情
答案 1 :(得分:-3)
这是我们的.h文件:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface AudioAndVideoViewController : UIViewController{
@public
}
MPMoviePlayerController *moviePlayer;
@property (nonatomic, retain) MPMoviePlayerController *moviePlayer;
- (IBAction) startPlayingVideo:(id)paramSender;
- (IBAction) stopPlayingVideo:(id)paramSender;
@end
- (IBAction) startPlayingVideo:(id)paramSender{
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *urlAsString = [mainBundle pathForResource:@"Sample" ofType:@"m4v"];
if (self.moviePlayer != nil)
{
[self stopPlayingVideo:nil];
}
MPMoviePlayerController *newMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.moviePlayer = newMoviePlayer; [newMoviePlayer release]; if (self.moviePlayer != nil){
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoHasFinishedPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
NSLog(@"Successfully instantiated the movie player.");
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[self.moviePlayer play];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
}
else {
NSLog(@"Failed to instantiate the movie player.");
}
}
- (IBAction) stopPlayingVideo:(id)paramSender
{
if (self.moviePlayer != nil){
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
[self.moviePlayer stop];
if (self.moviePlayer.view != nil && self.moviePlayer.view.superview != nil &&[self.moviePlayer.view.superview isEqual:self.view] == YES)
{
[self.moviePlayer.view removeFromSuperview];
}
}}