播放本地文件

 

#import <MediaPlayer/MPMoviePlayerController.h>
 
- (void)playMovieAtURL:(NSURL*)theURL
{
    MPMoviePlayerController* theMovie= [[MPMoviePlayerController alloc] initWithContentURL:theURL];
    theMovie.scalingMode=MPMovieScalingModeAspectFill;
    //    theMovie.userCanShowTransportControls=NO;
 
    // Register for the playback finished notification.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                            selector:@selector(myMovieFinishedCallback:)
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:theMovie];
 
    // Movie playback is asynchronous, so this method returns immediately.
    [theMovie play];
}
 
// When the movie is done,release the controller.
- (void)myMovieFinishedCallback:(NSNotification*)aNotification
{
    MPMoviePlayerController* theMovie=[aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
 
    // Release the movie instance created in playMovieAtURL
    [theMovie release];
} 
 
- (void)video_play:(NSString*)filename
{
    NSString* s = [[NSBundle mainBundle] pathForResource:filename ofType:@"m4v"];
    NSURL* url = [NSURL fileURLWithPath:s];
    NSLog(@"Playing URL: %@", url);
    [self playMovieAtURL:url];
}

 

要在C++中播放本地视频文件,你可以使用OpenCV库中的函数来实现。根据引用[1]中提供的信息,你可以使用`OpenAndPlayVideoFile`函数来打开和播放视频文件。该函数接受一个`std::string`类型的参数`filename`,表示视频文件的路径和名称。 下面是一个示例代码,演示了如何使用`OpenAndPlayVideoFile`函数来播放本地视频文件: ```cpp #include <iostream> #include <string> #include <opencv2/opencv.hpp> bool OpenAndPlayVideoFile(const std::string& filename); int main() { std::string filepath = "path/to/your/video/file.mp4"; if (OpenAndPlayVideoFile(filepath)) { std::cout << "视频播放成功!" << std::endl; } else { std::cout << "视频播放失败!" << std::endl; } return 0; } bool OpenAndPlayVideoFile(const std::string& filename) { cv::VideoCapture cap(filename); if (!cap.isOpened()) { std::cerr << "无法打开视频文件:" << filename << std::endl; return false; } cv::Mat frame; cv::namedWindow("Video Player", cv::WINDOW_NORMAL); while (cap.read(frame)) { cv::imshow("Video Player", frame); cv::waitKey(25); // 每帧显示间隔25毫秒,可以根据需要调整 } return true; } ``` 在上述代码中,首先定义了一个`OpenAndPlayVideoFile`函数,该函数接受一个视频文件的路径和名称作为参数。在函数内部,我们首先使用`cv::VideoCapture`类来打开视频文件。如果打开成功,我们会创建一个显示窗口并循环读取视频帧,并通过`cv::imshow`函数来显示每一帧。最后,我们使用`cv::waitKey`函数来等待用户按下键盘上的任意键退出播放。 你需要根据你的视频文件路径和名称,将代码中的`"path/to/your/video/file.mp4"`替换为实际的视频文件路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值