Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Basically , I get a url from webserver.I want to play a movie file from that url in an iPhone app.Please help! i mean to say my movie file is stored on webserver

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
273 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is the common way to play video file from server or from local path.


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

You can do using html5's video tag(provided you are using 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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...