2012-12-11 23 views
21

मैं एक एंड्रॉइड एप्लिकेशन विकसित कर रहा हूं जिसके लिए इसमें एक यूट्यूब वीडियो प्लेयर शामिल है। मुझे एपीआई से आरटीएसपी वीडियो यूआरएल सफलतापूर्वक मिला, लेकिन मेरे एंड्रॉइड वीडियो व्यू में इस आरटीएसपी यूआरएल को लोड करने का प्रयास करते समय, यह कहता है "Can't play this video."। पहले मैंने इस विधि में एक समान एप्लीकेशन विकसित किया था, और उस समय यह ठीक काम करता था, लेकिन यह अब भी लोड करने में असफल रहा।एंड्रॉइड वीडियो व्यू में यूट्यूब वीडियो कैसे खेलें?

मुझे यकीन है कि, मुझे एपीआई से सही आरटीएसपी यूआरएल मिल रहा है।

mVideoURL = getIntent().getStringExtra("EXT_URL"); 
    Log.i("VIDEO URL", " " + mVideoURL); 

    MediaController mc = new MediaController(this); 
    mVideoStreamView = (VideoView) findViewById(R.id.vidPlayer); 

    mVideoStreamView.setVideoURI(Uri.parse(mVideoURL)); 
    mVideoStreamView.setMediaController(mc); 
    mVideoStreamView.requestFocus(); 
    mVideoStreamView.start(); 

संपादित मिले logcat कुछ अतिरिक्त जानकारी:

ARTSPConnection(6607): status: RTSP/1.0 200 OK 
ASessionDescription(6607): v=0 
ASessionDescription(6607): o=GoogleStreamer 378992432 328144046 IN IP4 74.125.213.182 
ASessionDescription(6607): s=Video 
ASessionDescription(6607): c=IN IP4 0.0.0.0 
ASessionDescription(6607): b=AS:29 
ASessionDescription(6607): t=0 0 
ASessionDescription(6607): a=control:* 
ASessionDescription(6607): a=range:npt=0-1703.000000 
ASessionDescription(6607): m=video 0 RTP/AVP 98 
ASessionDescription(6607): b=AS:17 
ASessionDescription(6607): a=rtpmap:98 H263-2000/90000 
ASessionDescription(6607): a=control:trackID=0 
ASessionDescription(6607): a=cliprect:0,0,144,176 
ASessionDescription(6607): a=framesize:98 176-144 
ASessionDescription(6607): a=fmtp:98 profile=0;level=10 
ASessionDescription(6607): m=audio 0 RTP/AVP 99 
ASessionDescription(6607): b=AS:12 
ASessionDescription(6607): a=rtpmap:99 AMR/8000/1 
ASessionDescription(6607): a=control:trackID=1 
ASessionDescription(6607): a=fmtp:99 octet-align 
ARTSPConnection(6607): status: RTSP/1.0 200 OK 
ARTSPConnection(6607): status: RTSP/1.0 200 OK 
ARTSPConnection(6607): status: RTSP/1.0 200 OK 
ARTSPConnection(6607): status: RTSP/1.0 200 OK 
ARTSPConnection(6607): status: RTSP/1.0 200 OK 
ASessionDescription(6607): v=0 
ASessionDescription(6607): o=GoogleStreamer 1299458498 503248054 IN IP4 74.125.213.182 
ASessionDescription(6607): s=Video 
ASessionDescription(6607): c=IN IP4 0.0.0.0 
ASessionDescription(6607): b=AS:29 
ASessionDescription(6607): t=0 0 
ASessionDescription(6607): a=control:* 
ASessionDescription(6607): a=range:npt=0-1703.000000 
ASessionDescription(6607): m=video 0 RTP/AVP 98 
ASessionDescription(6607): b=AS:17 
ASessionDescription(6607): a=rtpmap:98 H263-2000/90000 
ASessionDescription(6607): a=control:trackID=0 
ASessionDescription(6607): a=cliprect:0,0,144,176 
ASessionDescription(6607): a=framesize:98 176-144 
ASessionDescription(6607): a=fmtp:98 profile=0;level=10 
ASessionDescription(6607): m=audio 0 RTP/AVP 99 
ASessionDescription(6607): b=AS:12 
ASessionDescription(6607): a=rtpmap:99 AMR/8000/1 
ASessionDescription(6607): a=control:trackID=1 
ASessionDescription(6607): a=fmtp:99 octet-align 
ARTSPConnection(6607): status: RTSP/1.0 461 Unsupported Transport 
ARTSPConnection(6607): status: RTSP/1.0 461 Unsupported Transport 

कृपया मुझे एंड्रॉयड वीडियो दृश्य में यूट्यूब वीडियो लोड करने के लिए एक तरह से सुझाव है rtsp://v6.cache6.c.youtube.com/CiULENy73wIaHAlV9VII3c64lRMYESARFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp

यहाँ मेरी गतिविधि कोड है ।

एडवांस में धन्यवाद ...

संपादित बस एक और डिवाइस में जाँच की, एचटीसी डिजायर (2.2)। कोड ठीक काम किया। मैं सोचने के बारे में सोच रहा हूं, नेक्सस (4.1) के साथ समस्या क्या होगी ??

+0

इसे जांचें: http://stackoverflow.com/questions/5162088/video-view-not-playing-youtube-video –

+0

आपको यूट्यूब का उपयोग करना चाहिए एंड्रॉइड के लिए एपीआई, यह बहुत आसान तरीका है – vuhung3990

+0

यह लिंक यह मदद करेगा .. http://www.truiton.com/2013/08/android-videoview-example-with-youtube-playback/ –

उत्तर

27

क्योंकि मुझे वीडियो दृश्य में आरटीएसपी यूआरएल लोड करने के लिए कोई रास्ता नहीं मिल रहा है (सभी डिवाइस & एंड्रॉइड संस्करणों के लिए), मैंने अपनी समस्या को हल करने के लिए एक और काम के साथ हल किया। मैंने यूट्यूब प्लेयर को एम्बेड करने के लिए एक वेबव्यू का उपयोग किया, और यह विधि सभी परीक्षण उपकरणों में अच्छी तरह से काम कर रही है।

mWebView.getSettings().setJavaScriptEnabled(true); 
mWebView.getSettings().setPluginState(PluginState.ON); 
mWebView.loadUrl("http://www.youtube.com/embed/" + videoID + "?autoplay=1&vq=small"); 
mWebView.setWebChromeClient(new WebChromeClient()); 

आप अपने सभी सहायता लोगों के लिए बहुत-बहुत धन्यवाद:

यहाँ मेरी कोड है।

+7

यह अनिवार्य रूप से डिवाइस में फ़्लैश प्लेयर होना चाहिए, लेकिन अब एंड्रॉइड (4.0 से ऊपर) अब फ्लैश सामग्री का समर्थन नहीं कर रहा है –

+0

इस लिंक का उपयोग करें .. http://www.truiton.com/2013/08/android-videoview-example-with-youtube-playback/ –

0

का उपयोग करना वीडियो देखें:

लेआउट एक्सएमएल में 1.Code:

<VideoView 

     android:layout_width=”wrap_content” 

     android:layout_height=”wrap_content” 

     android:id=”@+id/YoutubeVideoView” /> 

जावा वर्ग में 2.Code:

VideoView v = (VideoView) findViewById(R.id.YoutubeVideoView); 

v.setVideoURI(Uri.parse(“rtsp://v4.cache3.c.youtube.com/CjYLENy73wIaLQlW_ji2apr6AxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOr_86Xm06e5UAw=/0/0/0/video.3gp”)); 

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

// MediaController containing controls for a MediaPlayer        

v.requestFocus();//give focus to a specific view 

v.start();//starts the video 

हम 3gp लिंक निर्दिष्ट द्वारा VIDEOURI सेट मोबाइल प्लेटफ़ॉर्म के लिए यूट्यूब वीडियो का। मीडिया नियंत्रण जैसे प्ले, पॉज़, रिवाइंड, फास्ट फॉरवर्ड और एक प्रगति स्लाइडर जोड़ने के लिए, हम VideoController को VideoView में जोड़ते हैं।

uri.parse (वीडियो की 3gp लिंक) ... आप यूट्यूब

+0

मैं भी इसी विधि का उपयोग कर रहा हूं, लेकिन वीडियो लोड नहीं हो रहा है। मुझे लगता है कि यह मेरे नेटवर्क में आरटीएसपी प्रोटोकॉल समस्या हो सकती है। मैंने कुछ प्रश्नों को शामिल करने के लिए अपना प्रश्न संपादित किया। कृपया एक नज़र डालें .. आपके समय के लिए धन्यवाद .. – Midhu

+0

मैं एक और कोड पोस्ट कर रहा हूं जो आपको वीडियो के लिए आरटीएसपी यूआरएल प्राप्त करने में मदद करता है .. होप इससे आपकी मदद मिलेगी ..... –

+0

बस इसे जांचें ... –

14
private class YourAsyncTask extends AsyncTask<Void, Void, Void> 
    { 
     ProgressDialog progressDialog; 

     @Override 
     protected void onPreExecute() 
     { 
      super.onPreExecute(); 
      progressDialog = ProgressDialog.show(AlertDetail.this, "", "Loading Video wait...", true); 
     } 

     @Override 
     protected Void doInBackground(Void... params) 
     { 
      try 
      { 
       String url = "http://www.youtube.com/watch?v=1FJHYqE0RDg"; 
       videoUrl = getUrlVideoRTSP(url); 
       Log.e("Video url for playing=========>>>>>", videoUrl); 
      } 
      catch (Exception e) 
      { 
       Log.e("Login Soap Calling in Exception", e.toString()); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void result) 
     { 
      super.onPostExecute(result); 
      progressDialog.dismiss(); 
/* 
      videoView.setVideoURI(Uri.parse("rtsp://v4.cache1.c.youtube.com/CiILENy73wIaGQk4RDShYkdS1BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp")); 
      videoView.setMediaController(new MediaController(AlertDetail.this)); 
      videoView.requestFocus(); 
      videoView.start();*/    
      videoView.setVideoURI(Uri.parse(videoUrl)); 
      MediaController mc = new MediaController(AlertDetail.this); 
      videoView.setMediaController(mc); 
      videoView.requestFocus(); 
      videoView.start();   
      mc.show(); 
     } 

    } 

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; 
    } 
+0

मैं हूं यूट्यूब एपीआई से सफलतापूर्वक आरटीएसपी यूआरएल प्राप्त करना। मेरी समस्या यह है कि, मैं उस वीडियो यूआरएल में उस यूआरएल को लोड करने में सक्षम नहीं हूं। मुझे अभी यह पता चला है कि समस्या मेरे नेटवर्क में कुछ आरटीएसपी प्रोटोकॉल सेटिंग्स से संबंधित है। – Midhu

+0

तो यह काम करता है .... इस –

+0

को लागू करने में ऐसी कोई समस्या नहीं है नेटवर्क सेटिंग्स –

0

यह जो वीडियो कोडेक प्रारूप है कि आप अपने RTSP प्राप्त कर रहे हैं पर निर्भर करता है से प्राप्त कर सकते हैं। कुछ ऐसे डिवाइस हैं जो चल रहे .mp4 फ़ाइल का समर्थन नहीं करते हैं। अधिक जानकारी के लिए Android Media support के माध्यम से जाएं। जांचें कि क्या आप किसी अन्य .3 जीपी फाइलें चला सकते हैं या नहीं।

+0

मुझे यूट्यूब एपीआई से आरटीएसपी वीडियो यूआरएल प्राप्त हो रहा है। वे .3 जीपी फाइलें हैं। क्या उस वीडियो को लोड करने का कोई तरीका है ' VideoView', एंड्रॉइड संस्करण 4.1। 2.2 संस्करण के साथ कोड का प्रयास करते समय मुझे सही आउटपुट मिल रहा है। आपके समय के लिए धन्यवाद। – Midhu

3

YouTube के वर्तमान संस्करण के कारण आपको "इस वीडियो को नहीं चलाया जा सकता" त्रुटि प्राप्त होने की संभावना है यदि आप अपना वीडियो दिखाने के लिए VideoView का उपयोग करेंगे।

YouTubePlayerView के साथ इस approcach पर एक नज़र डालें: http://xinyustudio.wordpress.com/2014/03/17/android-development-play-youtube-video-in-your-app-cant-play-this-video-and-troubleshooting/

1

चेकआउट इस link। यह वीडियो व्यू में यूट्यूब वीडियो को कार्यान्वित करने का तरीका बताता है।

1

यूट्यूब एंड्रॉइड प्लेयर एपीआई का प्रयोग करें। यह पूरी तरह से काम करता है। यहां से मेरी उदाहरण की जाँच करें:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

tools:context="com.example.andreaskonstantakos.vfy.MainActivity"> 

<com.google.android.youtube.player.YouTubePlayerView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:visibility="visible" 
android:layout_centerHorizontal="true" 
android:id="@+id/youtube_player" 
android:layout_alignParentTop="true" /> 

<Button 
android:text="Button" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true" 
android:layout_marginBottom="195dp" 
android:visibility="visible" 
android:id="@+id/button" /> 


</RelativeLayout> 

MainActivity.java:

package com.example.andreaskonstantakos.vfy; 


import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import com.google.android.youtube.player.YouTubeBaseActivity; 
import com.google.android.youtube.player.YouTubeInitializationResult; 
import com.google.android.youtube.player.YouTubePlayer; 
import com.google.android.youtube.player.YouTubePlayerView; 



public class MainActivity extends YouTubeBaseActivity { 

YouTubePlayerView youTubePlayerView; 
Button button; 
YouTubePlayer.OnInitializedListener onInitializedListener; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player); 
    button = (Button) findViewById(R.id.button); 


    onInitializedListener = new YouTubePlayer.OnInitializedListener(){ 

     @Override 
     public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) { 

      youTubePlayer.loadVideo("Hce74cEAAaE"); 

      youTubePlayer.play(); 
    } 

     @Override 
     public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) { 

     } 
    }; 

    button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

youTubePlayerView.initialize(PlayerConfig.API_KEY,onInitializedListener); 
     } 
    }); 
} 
} 

और PlayerConfig.java वर्ग:

package com.example.andreaskonstantakos.vfy; 

/** 
* Created by Andreas Konstantakos on 13/4/2017. 
*/ 

public class PlayerConfig { 

PlayerConfig(){} 

public static final String API_KEY = 
"xxxxx"; 
} 

बदलें "Hce74cEAAaE "https://www.youtube.com/watch?v=Hce74cEAAaE से आपकी वीडियो आईडी के साथ। Console.developers.google.com से अपना API_KEY प्राप्त करें और इसे PlayerConfig.API_KEY पर भी बदलें। किसी और जानकारी के लिए आप निम्न ट्यूटोरियल चरण का पालन करके चरणबद्ध कर सकते हैं: https://www.youtube.com/watch?v=3LiubyYpEUk

+0

हालांकि यह लिंक प्रश्न का उत्तर दे सकता है, यह आवश्यक है कि आवश्यक यहां उत्तर के कुछ हिस्सों और संदर्भ के लिए लिंक प्रदान करते हैं। लिंक किए गए पृष्ठ में परिवर्तन होने पर लिंक-केवल उत्तर अमान्य हो सकते हैं। - [समीक्षा से] (/ समीक्षा/कम गुणवत्ता वाली पोस्ट/15827116) –

+1

मुझे लगता है कि यह अब उपयोगी है। –

संबंधित मुद्दे