Youtube Video Playing issue in Android - Code Attached
This is a critical issue pertaining to an application we did. The code snippet attached here was working like a charm for the past several months. All of a sudden, it gives us the message in mediaplayer that video cannot be played.
Can anyone please suggest what need to be done, in order that this code will work for me by playing the video with no hassles.
Looking forward for your valuable comments, help and suggestions,
Please follow this link in order to view the code which was working perfectly -- http://pastebin.com/NVT8eBC0
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class videoact extends Activity implements OnPreparedListener{
/** Called when the activity is first created. */
@Overr开发者_如何学JAVAide
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaController mc = new MediaController(this);
VideoView vv = (VideoView)findViewById(R.id.VideoView01);
try
{
Uri ur = Uri.parse("http://youtube.com/get_video?video_id=ZmX7zLCrcAI&t=vjVQa1PpcFPmrj_j5y370BhPYfq3qHoWsFICYcBqEl4%3D&asv=&fmt=18");
vv.setVideoURI(ur);
vv.setMediaController(mc);
vv.requestFocus();
vv.start();
mc.show();
}
catch(Exception e)
{
System.out.print(e.getMessage() + "error");
}
}
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.start();
}
}
You can't play YouTube videos like that. Use the Android YouTube Player Api or the IFrame API in a WebView. Using the get_video endpoint is against youtube's terms of service. https://www.youtube.com/static?template=terms
You agree not to access Content through any technology or means other than the video playback pages of the Service itself, the Embeddable Player, or other explicitly authorized means YouTube may designate.
精彩评论