How to play Video from Youtube by ID on Android?

All your problems with Audio, Video and Images.

How to play Video from Youtube by ID on Android?

Postby checkcheck » Tue Aug 16, 2011 8:02 am

I will create the app which must to play video file from youtube. I can do that with launch new Intent, but I must play video in my app, without other applications. For example, I can use SurfaceView, VideoView and other. But I never work with Youtube Player API and I don't know to do that correctly. For example I found this code:

Code: Select all
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class AnVideoView extends Activity {

String SrcPath = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
       myVideoView.setVideoURI(Uri.parse(SrcPath));
       myVideoView.setMediaController(new MediaController(this));
       myVideoView.requestFocus();
       myVideoView.start();
   }
}


But video isn't loaded ( I think that problem is rtsp protocol. I very NEED to create this app, help me please to fix mistakes or alternative way to play video from youtube without new intent. Thank you.
checkcheck
Freshman
Freshman
 
Posts: 3
Joined: Tue Aug 16, 2011 7:50 am

Top

Re: How to play Video from Youtube by ID on Android?

Postby checkcheck » Sat Aug 20, 2011 12:38 pm

Now I have a new porblem: I saw many applications which can download video from m.youtube.com, but I don't know how to do it and I must do it. Help me please, give me an example or idea please. Thank you, anyway
checkcheck
Freshman
Freshman
 
Posts: 3
Joined: Tue Aug 16, 2011 7:50 am

Re: How to play Video from Youtube by ID on Android?

Postby stece » Tue Aug 23, 2011 11:28 am

I once wrote an app that plays a youtube video using a WebView.

Code: Select all
WebView mWebView;
String temp = "<object width='400' height='200'>" +
   "<param name='movie' value='http://www.youtube.com/v/DZi6DEJsOJ0?fs=1&amp;hl=nl_NL'>" +
   "</param><param name='allowFullScreen' value='false'>" +
   "</param><param name='allowscriptaccess' value='always'>" +
   "</param><embed src='http://www.youtube.com/v/DZi6DEJsOJ0?fs=1&amp;hl=nl_NL'" +
   " type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='false'" +
   " width='400' height='200'></embed></object>";


mWebView = (WebView) findViewById(R.id.webviewOriginal);
          mWebView.getSettings().setJavaScriptEnabled(true);
          mWebView.getSettings().setPluginsEnabled(true);
          mWebView.setBackgroundColor(Color.BLACK);
          mWebView.loadData(temp,"text/html", "utf-8");



I don't know how to download the video. If I'm not mistaken the mp4 of the video is somewhere in the headers of the page. You could get it from there?
User avatar
stece
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Wed Apr 21, 2010 10:50 am
Location: Belgium

Re: How to play Video from Youtube by ID on Android?

Postby aaren » Fri Sep 02, 2011 10:22 am

Good Work.thanks for share it.
Aaren from mobile app development
aaren
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Sep 02, 2011 5:57 am

Re: How to play Video from Youtube by ID on Android?

Postby brusmartin » Tue Oct 18, 2011 7:38 am

Great job ! thanks for share it.

Brus Martin from blackberry app development
brusmartin
Freshman
Freshman
 
Posts: 2
Joined: Tue Oct 18, 2011 6:28 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 21 guests