IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants graphiques Android Discussion :

VideoView : Gestion de "Cette vidéo ne peut pas être lue"


Sujet :

Composants graphiques Android

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 149
    Points : 59
    Points
    59
    Par défaut VideoView : Gestion de "Cette vidéo ne peut pas être lue"
    Bonjour,

    Pour commencer voilà le code que j'ai écrit, je vais expliquer mon problème plus bas ;-)

    MainActivity.java :

    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;
            }
        }
     
    }
    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
    <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>
    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
    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>
    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.
    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 :
    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
    Merci d'avance pour votre aide !

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 149
    Points : 59
    Points
    59
    Par défaut
    J'ai réussi à gérer la fermeture de mon ProgressDialog via :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    camera_video.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                    @Override
                    public boolean onError(MediaPlayer mp, int what, int extra) {
                        Log.w("onError", "(" + Integer.toString(what) + "," + Integer.toString(extra) + ")");
                        pDialog.dismiss();
                        return false;
                    }
                });
    Par contre j'ai toujours l'AlertDialog qui apparaît, et ça je ne trouve pas comment l'enlever...

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 149
    Points : 59
    Points
    59
    Par défaut
    Ce qui est étrange c'est que les vidéos, provenant des URL que j'ai préciser dans le code, peuvent être lues seulement lorsque je suis connecté à Internet via les données mobile.
    Lorsque je me mets en Wifi, j'ai le message "Cette vidéo ne peut pas être lue"... Avez-vous déjà eu ce genre de problème ?

    Avec l'application "RTSP Player", j'arrive pourtant à lire la vidéo provenant de NewYork Times Square, que je sois en Wifi ou en données mobiles, alors que j'utilise la même URL dans mon l'application.
    L'URL est le suivant : rtsp://video2.earthcam.com/fecnetwork/4017timessquare.flv

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 149
    Points : 59
    Points
    59
    Par défaut
    J'ai réussi à ne pas afficher l'AlertDialog à l'aide de :
    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
    camera_video.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                    @Override
                    public boolean onError(MediaPlayer mp, int what, int extra) {
                        Log.w("onError", "(" + Integer.toString(what) + "," + Integer.toString(extra) + ")");
                        camera_textview.setText("Error");
                        String errorWhat;
                        switch(what){
                            case MediaPlayer.MEDIA_ERROR_UNKNOWN:
                                errorWhat = "MEDIA_ERROR_UNKNOWN";
                                break;
                            case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
                                errorWhat = "MEDIA_ERROR_SERVER_DIED";
                                break;
                            default:
                                errorWhat = "!";
                        }
                        String errorExtra;
                        switch(extra){
                            case MediaPlayer.MEDIA_ERROR_IO:
                                errorExtra = "MEDIA_ERROR_IO";
                                break;
                            case MediaPlayer.MEDIA_ERROR_MALFORMED:
                                errorExtra = "MEDIA_ERROR_MALFORMED";
                                break;
                            case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
                                errorExtra = "MEDIA_ERROR_UNSUPPORTED";
                                break;
                            case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
                                errorExtra = "MEDIA_ERROR_TIMED_OUT";
                                break;
                            default:
                                errorExtra = "!";
                        }
                       Log.w("Error", errorWhat + ", " + errorExtra);
                        mp.release();
                        return true;
                    }
                });
    Par contre toujours le même problème avec le wifi. Je vais ouvrir une autre discussion plutôt pour ce problème.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    149
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 149
    Points : 59
    Points
    59
    Par défaut
    Finalement ça viendrait d'un problème de pare-feu du Wifi ;-)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 9
    Dernier message: 27/03/2014, 17h10
  2. Mémoire ne peut pas être read
    Par tedparker dans le forum Access
    Réponses: 4
    Dernier message: 27/09/2006, 11h54
  3. Liens URL : La mémoire ne peut pas être "read" ?
    Par fredfred dans le forum Windows XP
    Réponses: 4
    Dernier message: 28/07/2006, 08h48
  4. Réponses: 2
    Dernier message: 21/07/2006, 06h55
  5. Réponses: 6
    Dernier message: 03/09/2003, 10h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo