Back to project page YouTubePlayerActivity.
The source code is released under:
MIT License
If you think the Android project YouTubePlayerActivity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.thefinestartist.ytpa.utils; //from w w w .j a va2s .c om import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by TheFinestArtist on 2/15/15. */ public class YouTubeUrlParser { // (?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11}) final static String reg = "(?:youtube(?:-nocookie)?\\.com\\/(?:[^\\/\\n\\s]+\\/\\S+\\/|(?:v|e(?:mbed)?)\\/|\\S*?[?&]v=)|youtu\\.be\\/)([a-zA-Z0-9_-]{11})"; public static String getVideoId(String videoUrl) { if (videoUrl == null || videoUrl.trim().length() <= 0) return null; Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(videoUrl); if (matcher.find()) return matcher.group(1); return null; } public static String getVidoeUrl(String videoId) { return "http://youtu.be/" + videoId; } }