【问题标题】:Playing a video file from server in an Iphone app在 Iphone 应用程序中从服务器播放视频文件
【发布时间】:2011-02-16 10:19:56
【问题描述】:

基本上,我从网络服务器获得一个 url。我想在 iPhone 应用程序中从该 url 播放电影文件。请帮忙!我的意思是说我的电影文件存储在网络服务器上

【问题讨论】:

    标签: iphone


    【解决方案1】:

    这是从服务器或本地路径播放视频文件的常用方法。

    
    MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: myURL];
    [[player view] setFrame: [myView bounds]];  // frame must match parent view
    [myView addSubview: [player view]];
    [player play];
    

    你可以使用html5的video标签(前提是你使用的是UIWebView)。

    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        //to play from actual server location
        //[self playVideo:@"file://localhost/Users/PlayVideos/3idiots.mov" frame:CGRectMake(20, 70, 280, 250)];
    
            //from server (http://www.example.com/video.mov)..... http://www.ebookfrenzy.com/ios_book/movie/movie.mov
        [self playVideo:@"your server URL" frame:CGRectMake(20, 70, 280, 250)];
    }
    
    - (void)playVideo:(NSString *)urlString frame:(CGRect)frame {
        NSString *embedHTML = @"\
        <html><head>\
        <style type=\"text/css\">\
        body {\
        background-color: transparent;\
        color: white;\
        }\
        </style>\
        <script>\
        function load(){document.getElementById(\"yt\").play();}\
        </script>\
        </head><body onload=\"load()\"style=\"margin:0\">\
        <video id=\"yt\" src=\"%@\" \
        width=\"%0.0f\" height=\"%0.0f\" autoplay controls></video>\
        </body></html>";
        NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
        UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
        [videoView loadHTMLString:html baseURL:nil];
        [self.view addSubview:videoView];
        [videoView release];
        NSLog(@"%@",html);
    }
    

    【讨论】:

    • 直接在设备上试试上面的代码,因为模拟器中没有Quick Player,它会直接在设备上运行!
    • @Swastik 请立即查看!
    • @Mayur 你能帮我检测播放按钮触摸事件吗?或者我可以只播放特定时间的电影
    【解决方案2】:

    从一个 url 播放来自网络服务器的视频

    viewDidLoad{
    movieURL=[NSURL URLWithString:@"http://www.samkeeneinteractivedesign.com/videos/littleVid3.mp4"];
    
    
    moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    if ([moviePlayer respondsToSelector:@selector(loadState)]) 
    {
        // Set movie player layout
        [moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
        [moviePlayer setFullscreen:YES];
        //  moviePlayer.view.frame = CGRectMake(10,10,1024,760);
        // May help to reduce latency
        [moviePlayer prepareToPlay];
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-24
      • 2014-09-21
      • 1970-01-01
      • 2011-11-16
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多