Necessito de passar um video através do link para dentro da minha app android , eu tentei este código :
String video="http://www.youtube.com/embed/76JpysFZ2VM";
Uri uri= Uri.parse(video);
vid1.setVideoURI(uri);
vid1.start();
Código completo :
package com.eu.agendamarinhagrande;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.StrictMode;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.VideoView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
public class Index extends AppCompatActivity {
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
// JSONParser jParser = new JSONParser();
int a;
// products JSONArray
public TextView descricao1;
public TextView descricao2;
public TextView descricao3;
public TextView descricao4;
public TextView descricao5;
public TextView descricao6;
public TextView videodescricao1;
public TextView videodescricao2;
public TextView videodescricao3;
public TextView videodescricao4;
public TextView videodescricao5;
public TextView videodescricao6;
public TextView videodescricao7;
public ImageView img1, img2, img4 , img3, img5 , img6;
public VideoView vid1;
ListView lista;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
setContentView(R.layout.single_post);
descricao1 = (TextView) findViewById(R.id.tvdescricao);
descricao2 = (TextView) findViewById(R.id.tvdescricao2);
descricao3 = (TextView) findViewById(R.id.tvdescricao3);
descricao4 = (TextView) findViewById(R.id.tvdescricao4);
descricao5 = (TextView) findViewById(R.id.tvdescricao5);
descricao6 = (TextView) findViewById(R.id.tvdescricao6);
videodescricao1 = (TextView) findViewById(R.id.tvdescricaovideo1);
videodescricao2 = (TextView) findViewById(R.id.tvdescricaovideo2);
videodescricao3 = (TextView) findViewById(R.id.tvdescricaovideo3);
videodescricao4 = (TextView) findViewById(R.id.tvdescricaovideo4);
videodescricao5 = (TextView) findViewById(R.id.tvdescricaovideo5);
videodescricao6 = (TextView) findViewById(R.id.tvdescricaovideo6);
videodescricao7 = (TextView) findViewById(R.id.tvdescricaovideo7);
img1 = (ImageView) findViewById(R.id.img1);
VideoView vid1=(VideoView) findViewById(R.id.videoView);
img2 = (ImageView) findViewById(R.id.img2);
img3 = (ImageView) findViewById(R.id.img3);
img4 = (ImageView) findViewById(R.id.img4);
img5 = (ImageView) findViewById(R.id.img5);
img6 = (ImageView) findViewById(R.id.img6);
String descricao = getIntent().getExtras().getString("descricao");
String imagens = getIntent().getExtras().getString("imagens");
String[] img = imagens.split(";");
String video="http://www.youtube.com/embed/76JpysFZ2VM";
Uri uri= Uri.parse(video);
System.out.println("URI"+uri);
vid1.setVideoURI(uri);
vid1.start();
int i;
String[] s = descricao.split("Imagem [0-5]+");
for (i = 0; i < s.length; i++) {
if (i == 0) {
if (img.length >= 1) {
descricao1.setText(s[i]);
URL url = null;
try {
url = new URL("http://www.cm-mgrande.pt" + img[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream input = url.openConnection().getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(input);
input.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
in.close();
img1.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
}
} if (i == 1) {
descricao2.setText(s[i]);
if (img.length >= 2) {
URL url = null;
try {
url = new URL("http://www.cm-mgrande.pt" + img[1]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream input = url.openConnection().getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(input);
input.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
in.close();
img2.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (i == 2) {
descricao3.setText(s[i]);
if (img.length >= 3) {
{
URL url = null;
try {
url = new URL("http://www.cm-mgrande.pt" + img[2]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream input = url.openConnection().getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(input);
input.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
in.close();
img3.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}if (i == 3) {
descricao4.setText(s[i]);
if (img.length >= 4) {
URL url = null;
try {
url = new URL("http://www.cm-mgrande.pt" + img[3]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream input = url.openConnection().getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(input);
input.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
in.close();
img4.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (i == 4)
{
descricao5.setText(s[i]);
if (img.length >= 5) {
URL url = null;
try {
url = new URL("http://www.cm-mgrande.pt" + img[4]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream input = url.openConnection().getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(input);
input.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
in.close();
img5.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
}
}if (i == 5)
{
descricao6.setText(s[i]);
if (img.length >= 6) {
URL url = null;
try {
url = new URL("http://www.cm-mgrande.pt" + img[5]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream input = url.openConnection().getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(input);
input.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
in.close();
img6.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
Não obtive sucesso. Alguém me poderia ajudar?
Preciso de um código não muito grande e facil de se entender!