Note that there are some explanatory texts on larger screens.

plurals
  1. PODownloading 3gp Video from Youtube Rtsp URL on Android
    primarykey
    data
    text
    <p>I'm trying to download the 3gp video file from Youtube's rtsp URL and save it to my external storage, but it appears that the method I have only works with HTTP URL.</p> <p>I received this warning:</p> <pre><code>09-02 10:32:40.877: WARN/System.err(7988): java.net.MalformedURLException: Unknown protocol: rtsp </code></pre> <p>My download method is the following:</p> <pre><code>public static void downloadFromURL(String url, File cacheDir, String fileName) throws IOException { long startTime = System.currentTimeMillis(); String TAG = "DL"; if (url != null) { if (fileName.contains("/")) fileName = fileName.replace("/", "-"); url = url.replace(" ", "%20"); URL mUrl = new URL(url); URLConnection ucon = mUrl.openConnection(); ucon.setReadTimeout(TIMEOUT_CONNECTION); ucon.setConnectTimeout(TIMEOUT_SOCKET); File f = new File(cacheDir, fileName); InputStream is = ucon.getInputStream(); BufferedInputStream inStream = new BufferedInputStream(is, BUFFER_SIZE); FileOutputStream outStream = new FileOutputStream(f); byte[] buff = new byte[BUFFER_SIZE]; int len; while ((len = inStream.read(buff)) != -1) { outStream.write(buff, 0, len); } // clean up outStream.flush(); outStream.close(); inStream.close(); android.util.Log.d(TAG, "Download completed in " + ((System.currentTimeMillis() - startTime) / 1000) + " sec"); } } </code></pre> <p>FYI I test it on my Nexus 7 with Wi-Fi connection. Let me know if anybody has the solution to the problem I'm having.</p> <p><strong>UPDATE</strong></p> <p>Anyway, I found these Objective-C snippets which do the request I need, but I'm clueless to turn it into Java codes:</p> <pre><code>NSString *urlString = @"http://www.youtube.com/get_video_info?&amp;video_id=7ubt8AWa7SU"; //7ubt8AWa7SU gylfmQgtMJc NSURL *infoUrl = [NSURL URLWithString:urlString]; NSError *error = NULL; NSString *info = [NSString stringWithContentsOfURL:infoUrl encoding:NSUTF8StringEncoding error:&amp;error]; if (info == nil) { NSLog(@"Error: %@", [error description]); return; } NSArray *urlComponents = [info componentsSeparatedByString:@"&amp;"]; NSArray *itemComponents; NSString *urlEncodedFmtStreamMap = NULL; for (NSString *item in urlComponents) { itemComponents = [item componentsSeparatedByString:@"="]; if (itemComponents) { NSString *first = [itemComponents objectAtIndex:0]; if ([first isEqualToString: @"url_encoded_fmt_stream_map"]) { urlEncodedFmtStreamMap = [itemComponents objectAtIndex:1]; break; } } } NSString *type = NULL; NSString *urlSeg1 = NULL; NSString *sig = NULL; if (urlEncodedFmtStreamMap) { NSArray *formats = [[urlEncodedFmtStreamMap stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] componentsSeparatedByString:@","]; for (NSString *item in formats) { type = NULL; urlSeg1 = NULL; sig = NULL; NSArray *pairs = [item componentsSeparatedByString:@"&amp;"]; for (NSString *pair in pairs) { NSArray *varComps = [pair componentsSeparatedByString:@"="]; NSString *varName = [varComps objectAtIndex: 0]; NSString *varValue = [[varComps objectAtIndex: 1] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; if ([varName isEqualToString: @"type"]) { NSArray *typeSegments = [varValue componentsSeparatedByString: @";"]; type = [typeSegments objectAtIndex:0]; } else if ([varName isEqualToString: @"url"]) { urlSeg1 = [varValue stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; } else if ([varName isEqualToString: @"sig"]) { sig = varValue; } } if ([type isEqualToString:@"video/mp4"] &amp;&amp; urlSeg1 &amp;&amp; sig) { self.videoUrl = [[urlSeg1 stringByAppendingString: @"&amp;signature="] stringByAppendingString: sig]; break; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload