bonjour a tous
je vient vers vous car je suis débutant en java et je n'arrive pas a lire une video url mp4
je cherche sur internet mais rien qui fonction correctement
ou quand je trouve un sample qui fonctionne il y a tellement d'activity ou option que je suis totalement perdu
voici ce que je fait
dans le manifeste.xml
Code:<uses-permission android:name="android.permission.INTERNET" />
dans le activity_main.xml
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <VideoView android:id="@+id/videoView" android:layout_width="413dp" android:layout_height="250dp" android:layout_marginTop="101dp" android:layout_marginBottom="380dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
dans le MainActivity
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.widget.VideoView; public class MainActivity extends AppCompatActivity { private VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); videoView = (VideoView) findViewById(R.id.videoView); Uri video = Uri.parse("http://highlight-formation.fr/teste/frn118lesacn.mp4"); videoView.setVideoURI(video); videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setLooping(true); videoView.start(); } }); } }
merci d'avance