ios - 如何播放服务器上的在线视频
<p><p>我的服务器上有视频。我想在 iPhone 和 iPad 上播放这些视频。</p>
<p>谁能建议如何处理这种情况? </p>
<p>我知道如何在我的项目中使用 <code>MPMoviePlayerController</code> 播放视频。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以使用 WebView 播放视频。</p>
<p>在 .h 文件中添加以下代码:</p>
<pre><code>#import <MediaPlayer/MediaPlayer.h>
@interface VideoViewController : UIViewController<UIWebViewDelegate>
@property (nonatomic, strong) UIWebView *playerView;
</code></pre>
<p>在 .m 文件中:</p>
<pre><code>@synthesize playerView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = ;
if (self) {
self.playerView = [initWithFrame:CGRectMake(10, 05, 300, 200)];
;
}
return self;
}
-(void)viewDidLoad
{
playerView.delegate = self;
playerView.scrollView.scrollEnabled = NO;
playerView.layer.cornerRadius = 5.0;
playerView.clipsToBounds = YES;
}
</code></pre>
<p>并在 playBtn 操作中输入此代码:</p>
<pre><code>NSString *yourVideoLink = your video link;
NSString *yourlinkThumbnail = your video thumbnaillink;
;
#pragma mark - Webview Delegates
- (void)webViewDidStartLoad:(UIWebView *)webView
{
//;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// ;
}
#pragma mark - MoviePlayer Methods
- (void)playVideo:(NSString *)urlString withWebView:(UIWebView*)videoView andThumbnailLink:(NSString*)thumbnailImageLink {
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\" poster=\"%@\" autoplay controls></video>\
</body></html>";
videoView.backgroundColor =;
NSString *html = ;
;
[ addObserver:self selector:@selector(videoPlayStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[ addObserver:self selector:@selector(videoPlayFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
}
-(void)videoPlayStarted:(NSNotification *)notification{
//self.isInFullScreenMode = YES;
}
-(void)videoPlayFinished:(NSNotification *)notification{
// your code here
// self.isInFullScreenMode = NO;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何播放服务器上的在线视频,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/14681618/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/14681618/
</a>
</p>
页:
[1]