Bonjour, j'essaie de lire la vidéo du stockage interne du téléphone dans VideoView, mais mon téléphone affiche "Impossible de lire cette vidéo". J'obtiens un chemin vidéo dans l'activité principale en le transmettant à l'activité du projecteur.impossible de lire cette vidéo dans VideoView à partir de la carte SD
C'est le chemin: '/ stockage/émulé/0/stockage/émulé/0/snaptube/télécharger/SnapTube vidéo/Justin Bieber - Sorry (BUT _ Le Mouvement) .mp4'
code OnCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_projector);
Intent intent = getIntent();
String vidpath = intent.getExtras().getString("path");
p = (TextView) findViewById(R.id.videopath);
p.setText(vidpath);
Uri path= Uri.parse(Environment.getExternalStorageDirectory()+vidpath);
viewvid=(VideoView) this.findViewById(R.id.videoView);
Log.i("vidpath","here");
viewvid.setVideoURI(path);
viewvid.start();
}
Voilà comment j'obtenir le chemin de la vidéo à partir MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("Video Projector");
gall = (Button) findViewById(R.id.gallery);
gall.setOnClickListener(this);
}
@ Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_VIDEO) {
selectedVideoPath = getPath(data.getData());
if(selectedVideoPath == null) {
finish();
} else {
Toast.makeText(this,"A Video was selected",Toast.LENGTH_LONG).show();
Intent i = new Intent(this,projector.class);
i.putExtra("path",selectedVideoPath);
startActivity(i);
}
}
}
finish();
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if(cursor!=null) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
else return null;
}
@Override
public void onClick(View v) {
if (v==gall)
{
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECT_VIDEO);
}
}
Voici Log:
09 - 11 09: 48: 33.341 27291 - 27291/com.example.tabish.vidprojector W/MediaPlayer: Couldn 't open /storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4: java.io.FileNotFoundException: No content provider: /storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4
09 - 11 09: 48: 33.342 27291 - 27291/com.example.tabish.vidprojector I/MediaPlayer: setDataSource(/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry(PURPOSE _ The Movement).mp4)
09 - 11 09: 48: 33.342 547 - 628/? I/MediaPlayerService : setDataSource(/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry(PURPOSE _ The Movement).mp4)
09 - 11 09: 48: 33.365 547 - 27641/? E/FileSource : Failed to open file '/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4'.(No such file or directory)
** RESOLU: ** ** Etape1: ** Utiliser 'Uri path = Uri.fromFile (nouveau fichier (vidpath));' * * Étape 2: ** Vérifiez l'autorisation de stockage pour votre application dans le gestionnaire d'applications de votre téléphone. – Tabish
Affichez la solution dans la zone ** Votre réponse **. Merci –