Bonjour,
Pour commencer voilà le code que j'ai écrit, je vais expliquer mon problème plus bas ;-)
MainActivity.java :
activity_main.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 package com.example.etchelecou.fluxvideo; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.widget.TextView; import android.widget.VideoView; import android.net.Uri; import android.app.ProgressDialog; import android.util.Log; import android.media.MediaPlayer; import android.media.MediaPlayer.OnPreparedListener; import android.media.MediaPlayer.OnBufferingUpdateListener; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class MainActivity extends Activity { ProgressDialog pDialog; VideoView camera_video; TextView camera_textview; int choix_video = 1; String VideoURL_NewYork = "rtsp://video2.earthcam.com/fecnetwork/4017timessquare.flv"; String VideoURL_London = "rtsp://video2.earthcam.com/fecnetwork/AbbeyRoadHD1.flv"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); camera_video = (VideoView) findViewById(R.id.camera_video); camera_textview = (TextView) findViewById(R.id.camera_textview); camera_textview.setVisibility(View.INVISIBLE); ConnectionDetector connecte = new ConnectionDetector(this); if(connecte.isConnectingToInternet()) { try { pDialog = new ProgressDialog(this); if (choix_video == 1) { Uri video = Uri.parse(VideoURL_NewYork); camera_video.setVideoURI(video); pDialog.setTitle("New York - Times Square"); } else { Uri video = Uri.parse(VideoURL_London); camera_video.setVideoURI(video); pDialog.setTitle("London - Road Crossing"); } pDialog.setMessage("Buffering..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); } catch (Exception e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } camera_video.requestFocus(); camera_video.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener() { @Override public void onBufferingUpdate(MediaPlayer mp, int percent) { Log.v("Buffer", Integer.toString(percent)); pDialog.setMessage("Buffering... " + Integer.toString(percent) + "%"); if (percent == 100) { camera_video.start(); pDialog.dismiss(); } } }); } }); } else { camera_video.setVisibility(View.INVISIBLE); camera_textview.setVisibility(View.VISIBLE); camera_textview.setGravity(Gravity.CENTER); camera_textview.setText("Pas de connection\n\nNo connection"); } } public class ConnectionDetector { private Context _context; public ConnectionDetector(Context context){ this._context = context; } public boolean isConnectingToInternet(){ ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) for (int i = 0; i < info.length; i++) if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } return false; } } }
Et dans AndroidManifest.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <VideoView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/camera_video" android:layout_centerInParent="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/camera_textview" android:layout_centerInParent="true" /> </RelativeLayout>
Pour le moment l'application, à son lancement, vérifie s'il y a une connexion internet. Si oui, elle charge un flux vidéo qui provient d'une webcam dont l'URL est écrit en dur dans le code, si non, elle affiche un TextView. Pour plus tard, j'aimerais pouvoir donner la possibilité à l'utilisateur de rentrer l'URL. Si l'adresse ne permet pas de charger une vidéo, j'ai un AlertDialog qui apparaît : "Cette vidéo ne peut pas être lue" et quand je tape sur "OK" je retourne sur l'activité où j'ai mon ProgressDialog qui tourne encore.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.etchelecou.fluxvideo" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
J'aimerai donc pouvoir surcharger la méthode qui fait apparaître cet AlertDialog, pour qu'il n'affiche plus d'AlertDialog, et pour qu'il ferme le ProgressDialog et affiche le TextView avec un certain message. Le problème, c'est que je ne sait pas quelle fonction surcharger...
Voilà le LOG lorsque la vidéo ne peut pas être lue :
Merci d'avance pour votre aide !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 02-17 09:13:38.075 30527-30527/com.example.etchelecou.fluxvideo D/MediaPlayer﹕ Couldn't open file on client side, trying server side 02-17 09:13:38.085 30527-30527/com.example.etchelecou.fluxvideo V/MediaPlayer﹕ setVideoSurfaceTexture 02-17 09:13:38.085 30527-30527/com.example.etchelecou.fluxvideo V/MediaPlayer-JNI﹕ setAudioStreamType: 3 02-17 09:13:38.085 30527-30527/com.example.etchelecou.fluxvideo V/MediaPlayer﹕ MediaPlayer::setAudioStreamType 02-17 09:13:38.085 30527-30527/com.example.etchelecou.fluxvideo V/MediaPlayer﹕ setVideoSurfaceTexture 02-17 09:13:38.085 30527-30527/com.example.etchelecou.fluxvideo V/MediaPlayer﹕ prepareAsync 02-17 09:13:45.563 30527-30540/com.example.etchelecou.fluxvideo V/MediaPlayer﹕ message received msg=100, ext1=1, ext2=-2147483648 02-17 09:13:45.563 30527-30540/com.example.etchelecou.fluxvideo E/MediaPlayer﹕ error (1, -2147483648) 02-17 09:13:45.563 30527-30540/com.example.etchelecou.fluxvideo V/MediaPlayer﹕ callback application 02-17 09:13:45.563 30527-30540/com.example.etchelecou.fluxvideo V/MediaPlayer﹕ back from callback 02-17 09:13:45.563 30527-30527/com.example.etchelecou.fluxvideo E/MediaPlayer﹕ Error (1,-2147483648) 02-17 09:13:45.563 30527-30527/com.example.etchelecou.fluxvideo D/VideoView﹕ Error: 1,-2147483648 02-17 09:13:45.573 30527-30527/com.example.etchelecou.fluxvideo D/Dialog﹕ checkMirrorLinkEnabled returns : false 02-17 09:13:45.573 30527-30527/com.example.etchelecou.fluxvideo D/Dialog﹕ showing allowed 02-17 09:13:47.305 30527-30527/com.example.etchelecou.fluxvideo E/ViewRootImpl﹕ sendUserActionEvent() mView == null
Partager