0

I'm working on an app that takes URLs from RSS feeds and opens them in a video player. It works if the URL is directly to the mp4/whatever file, but if I have a redirected URL (e.g. This one which redirects here) my player crashes and fails.

Is there any way to detect if its redirecting, and to which URL?

Thanks in advance :)

Nick Badal
  • 681
  • 1
  • 8
  • 26

2 Answers2

1

for redirected url you may try this

try {
    HttpResponse response = client.execute(getRequest);
    final int statusCode = response.getStatusLine().getStatusCode();
    if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY){
        String location = response.getHeaders("Location")[0].toString();
        String redirecturl = location.replace("Location: ", "");
    }
}
tooolkit
  • 51
  • 2
  • Is there any way to not download the whole file? It takes like 30 seconds for me :( – Nick Badal Mar 08 '12 at 03:31
  • I solved my speed issue (somewhat) by storing the data on the device, so I marked this as the answer. I'm still curious if there's a way to speed this up? Thanks! – Nick Badal Mar 11 '12 at 20:29
  • @nickbadal You should download only the headers as described here, this will avoid downloading the data itself: http://stackoverflow.com/questions/8852392/http-get-only-download-the-header-head-is-not-supported – Tom Susel Jun 24 '13 at 20:04
  • This one helps? http://stackoverflow.com/a/5270162/609782 here they are using openConnection() and connectino.getResponseCode(). I am not sure whether openConnection downloads whole file or not. – Darpan Dec 10 '14 at 10:11
0

I made a test for you with my firefox10:
I typed your non-redirected url in my browser, and it will show the download page very soon, but for the redirected url, I aslo have to wait for a while to see the download page(more than 10s). So I guess accessing redirected url is much slower than the non-redirected one.

teoking
  • 127
  • 7