简体   繁体   English

iOS媒体播放器和JavaScript重定向

[英]iOS media player & javascript redirection

I have a php file that redirects to a video like: 我有一个php文件,该文件重定向到如下视频:

header('Location: site.com/video.mp4');

When I send this url to the media player 当我将此网址发送到媒体播放器时

[[MPMoviePlayerController alloc] initWithContentURL:@"http://mysite.com/my.php"];

it works fine, no problem, video is playing on media player. 它工作正常,没问题,视频正在媒体播放器上播放。

But now I need to do this in javascript's way. 但是现在我需要以javascript的方式执行此操作。 But I cant figure out how can I do this. 但是我不知道该怎么做。

When I do this in javascript, 当我使用javascript执行此操作时,

redirect.html: redirect.html:

<script>
   window.location.replace('www.site.com/video.mp4');
</script>

and send this url to the media player 并将此网址发送到媒体播放器

[[MPMoviePlayerController alloc] initWithContentURL:@"http://mysite.com/redirect.html"];

video does not come. 视频不来。

Any idea ? 任何想法 ? How can I do that ? 我怎样才能做到这一点 ?

It is not possible. 这不可能。 The video-player is not parsing the content of the returned file as HTML/JavaScript, but think it is a videostream. 视频播放器未将返回文件的内容解析为HTML / JavaScript,但认为它是视频流。 As the returned document is not a videostream the player will fail. 由于返回的文档不是视频流,因此播放器将失败。

If you need the server to tell the client what file/url to use you can return a JSON-object containing the URL and have the iOS-app use this as the video-url, but then a server redirect is both cleaner and easyer to implement. 如果您需要服务器告诉客户端要使用的文件/ URL,则可以返回一个包含URL的JSON对象,并让iOS应用将其用作视频URL,但是服务器重定向既干净又容易实行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM