Search code examples
javascriptobjective-ciosxcodemedia-player

iOS media player & javascript redirection


I have a php file that redirects to a video like:

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. But I cant figure out how can I do this.

When I do this in javascript,

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 ?


Solution

  • 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. 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.