jouer en streaming en VideoView, convertir url rtsp

J'ai besoin de lire des vidéos youtube et d'enregistrer des vidéos dans la même disposition.

Pour effectuer ce que je recherche pour l'api youtube et a constaté que la version android est plus élevé que 2.2, cette ok, mais, je veux utiliser VideoView.

J'ai vu quelques post ici sur cette question et décider finalement pour utiliser ce code pour voir la vidéo dans VideoView.

videoView = (VideoView) findViewById(R.id.your_video_view);

Log.d(TAG,getUrlVideoRTSP(current_url) + "  id yotube1  " );


//here type the url...
videoView.setVideoURI(Uri.parse(getUrlVideoRTSP(current_url)));



videoView.setMediaController(new MediaController(this)); //sets MediaController in the video view

videoView.requestFocus();//give focus to a specific view 
videoView.start();//starts the video

ce code fonctionne, mais juste avec rtsp lien comme ceci :

String exemple = "rtsp://v4.cache3.c.youtube.com/CjYLENy73wIaLQlW_ji2apr6AxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOr_86Xm06e5UAw=/0/0/0/video.3gp";

J'ai plusieurs lien dans l'url donc j'ai besoin de code pour convertir url RTSP, je ne peux pas le faire manuellement, je check un peu de code, et tous ne fonctionnent pas...

J'essaie ceci: à partir d'ici
Comment obtenir l'URL RTSP?

public static String getUrlVideoRTSP(String urlYoutube)
{
try
{
String gdy = "http://gdata.youtube.com/feeds/api/videos/";
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
String id = extractYoutubeId(urlYoutube);
URL url = new URL(gdy + id);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
Document doc = documentBuilder.parse(connection.getInputStream());
Element el = doc.getDocumentElement();
NodeList list = el.getElementsByTagName("media:content");///media:content
String cursor = urlYoutube;
for (int i = 0; i < list.getLength(); i++)
{
Node node = list.item(i);
if (node != null)
{
NamedNodeMap nodeMap = node.getAttributes();
HashMap<String, String> maps = new HashMap<String, String>();
for (int j = 0; j < nodeMap.getLength(); j++)
{
Attr att = (Attr) nodeMap.item(j);
maps.put(att.getName(), att.getValue());
}
if (maps.containsKey("yt:format"))
{
String f = maps.get("yt:format");
if (maps.containsKey("url"))
{
cursor = maps.get("url");
}
if (f.equals("1"))
return cursor;
}
}
}
return cursor;
}
catch (Exception ex)
{
Log.e("Get Url Video RTSP Exception======>>", ex.toString());
}
return urlYoutube;
}
protected static String extractYoutubeId(String url) throws MalformedURLException
{
String id = null;
try
{
String query = new URL(url).getQuery();
if (query != null)
{
String[] param = query.split("&");
for (String row : param)
{
String[] param1 = row.split("=");
if (param1[0].equals("v"))
{
id = param1[1];
}
}
}
else
{
if (url.contains("embed"))
{
id = url.substring(url.lastIndexOf("/") + 1);
}
}
}
catch (Exception ex)
{
Log.e("Exception", ex.toString());
}
return id;
}

Je utiliser la méthode ci-dessus comme ceci :

getUrlVideoRTSP(current_url)

quand currnt_url de test est :

current_url = "http://m.youtube.com/#/watch?v=FlsBObg-1BQ"

J'ai essayer ce code et ça ne fonctionne pas

private  class Syncyoutube extends AsyncTask <Void , Void , Void>{
@Override
protected void onPostExecute(Void result) {
//TODO Auto-generated method stub
super.onPostExecute(result);
/**
videoView.setMediaController(new MediaController(this)); //sets MediaController in the video view
//  MediaController containing controls for a MediaPlayer                                  
videoView.requestFocus();//give focus to a specific view 
videoView.start();//starts the video
*/
}
public String getRstpLinks(String code){
String[] urls = new String[3];
String link = "http://gdata.youtube.com/feeds/api/videos/" + code + "?alt=json";
String json = getJsonString(link); //here you request from the server
try {
JSONObject obj = new JSONObject(json);
String entry = obj.getString("entry");
JSONObject enObj = new JSONObject(entry);
String group = enObj.getString("media$group");
JSONObject grObj = new JSONObject(group);
String content = grObj.getString("media$content");
JSONObject cntObj = new JSONObject(group);
JSONArray array = grObj.getJSONArray("media$content");
for(int j=0; j<array.length(); j++){
JSONObject thumbs = array.getJSONObject(j);
String url = thumbs.getString("url");
urls[j] = url;
Log.d(TAG, url);
//data.setThumbUrl(thumbUrl);
}
Log.v(TAG, content);
} catch (Exception e) {
Log.e(TAG, e.toString());
urls[0] = urls[1] = urls[2] = null;
}
return urls[2];
}
public String getJsonString(String url){
Log.e("Request URL", url);
StringBuilder buffer = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet     request = new HttpGet( url );
HttpEntity entity = null;
try {
HttpResponse response = client.execute(request);
if( response.getStatusLine().getStatusCode() == 200 ){
entity = response.getEntity();
InputStream is = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
while( (line = br.readLine() )!= null ){
buffer.append(line);
}
br.close();
}
} catch (ClientProtocolException e) {
//TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
entity.consumeContent();
} catch (Exception e) {
Log.e(TAG, "Exception = " + e.toString() );
}
}
return buffer.toString();
}
@Override
protected Void doInBackground(Void... params) {
//TODO Auto-generated method stub
code = id_current_url(current_url);
//here type the url...
String rstp_url = getRstpLinks(code);
videoView.setVideoURI(Uri.parse(rstp_url));
//the code crech in this line because null exeption
//i chack this and discover that code variable is =tFXS9krT2VY , ok..
//but rstp_url variable in null 
Log.d(TAG,getRstpLinks(code) + "   idan id yotube1  " );
return null;
}
}
public String id_current_url (String url) {
String c_id = null ;
c_id = url.substring((url.lastIndexOf("=")), url.length());
return c_id ;
}   
}

le code d'un crash dans l' " videoView.setVideoURI(Uri.parse(rstp_url)); " la ligne parce null exeption
- je vérifier cela et de découvrir que le code de la variable est =tFXS9krT2VY , ok..
mais rstp_url variable à null


UdayKiran a écrit cette réponse similaire Q , quelqu'un pourrait expliquer ce qu'il signifie?
je ne comprends pas sa réponse

sa réponse :

Element rsp = (Element)entry.getElementsByTagName("media:content").item(1);
String anotherurl=rsp.getAttribute("url");

Dans gdata api seulement nous obtenons ce type de liens : rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANfeggugz2awrlb3mm/0/0/0/vidéo.3gp

Ces jouent dans VideoView.


enfin, je ne utiliser ce code et videoview pour la cuisson à la vapeur

- je utiliser youtube api android , c'est un travail à partir d'android 2.2 pas de 4,2 comme je l'ai
écrit dans mon Q , il a été mastake.

le résultat de l'utilisation rtsp c'est la mauvaise qualité de la vidéo et la nécessité de traiter avec un ratio d'aspect.

J'ai une appli où je joue de youtube dans une videoview. Mais malheureusement, votre question n'est pas claire. Quel est le problème? Ce que vous voulez?
désolé si c'est pas clair : j'ai besoin d'un code qui a reçu youtube url comme ceci :current_url = "m.youtube.com/#/watch?v=FlsBObg-1BQ" et le retour rtsp comme ceci : String exemple = "rtsp://v4.cache3.c.youtube.com/CjYLENy73wIaLQlW_ji2apr6AxMYDSANfeijbxytz29vz2xlsarsbxdhdgnoyor_86xm06e5uaw=/0/0/0/video.3gp";
je trouve cette code.google.com/p/android-youtube-player/downloads/list mais certains vidéo à ne pas ouvrir avec cela et j'ai besoin d'utiliser de la vidéo de la vue, de sorte o ne pas l'utiliser
ok , vérifier ma réponse!

OriginalL'auteur idan | 2013-04-14