Problème videoplayer app, lire toutes les videos d'un dossier en loop [Résolu]

Signaler
-
 Armczbt -
Bonjour, je suis sur une appli de Video Player. Tout fonctionne bien mais j'aimerai faire en sorte que mes vidéos se loopent en bouclent dans un dossier. J'ai réussi à faire en sorte que la video se loop à sa fin mais je voudrais qu'elle passe à celle d'après à la fin.

Je vous mets une partie de mon code :

package com.armdev.advid.activity;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;
 
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
 
import com.armdev.advid.R;
import com.armdev.advid.VideoModel;
import com.armdev.advid.adapter.VideosAdapter;
 
import java.util.ArrayList;
import java.util.Locale;
 
public class VideoFolder extends AppCompatActivity implements SearchView.OnQueryTextListener {
 
 
    private static final String MY_SORT_PREF = "sortOrder";
    private RecyclerView recyclerView;
    private String name;
    private ArrayList<VideoModel> videoModelArrayList = new ArrayList<>();
    private VideosAdapter videosAdapter;
 
 
    Toolbar toolbar;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_folder);
 
 
        name = getIntent().getStringExtra("folderName");
        recyclerView = findViewById(R.id.video_recyclerview);
        toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.back_arrow));
 
        int index = name.lastIndexOf("/");
        String onlyFolderName = name.substring(index+1);
        toolbar.setTitle(onlyFolderName);
        toolbar.setTitleTextAppearance(this, R.style.VarelaAppearance);
 
 
 
 
        loadVideos();
 
 
}
 
 
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_toolbar, menu);
        MenuItem menuItem = menu.findItem(R.id.search);
        SearchView searchView = (SearchView) menuItem.getActionView();
        ImageView ivClose = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
        ivClose.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.orange), PorterDuff.Mode.SRC_IN);
        searchView.setQueryHint("Rechercher un fichier");
        searchView.setOnQueryTextListener(this);
        return super.onCreateOptionsMenu(menu);
 
 
    }
 
    @Override
    public boolean onQueryTextSubmit(String query) {
        return false;
    }
 
    @Override
    public boolean onQueryTextChange(String newText) {
        String input = newText.toLowerCase();
        ArrayList<VideoModel> searchList = new ArrayList<>();
        for (VideoModel model : videoModelArrayList){
            if (model.getTitle().toLowerCase().contains(input)){
                searchList.add(model);
            }
        }
 
        videosAdapter.updateSearchList(searchList);
 
 
        return false;
    }
 
 
 
 
 
    public void loadVideos(){
 
        videoModelArrayList = getallVideoFromFolder(this, name);
 
 
 
        if (name!=null && videoModelArrayList.size()>0){
 
            videosAdapter = new VideosAdapter(videoModelArrayList, this);
            recyclerView.setAdapter(videosAdapter);
            recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
 
 
        }else {
            Toast.makeText(this, "Aucun dossier trouvé", Toast.LENGTH_SHORT).show();;
        }
 
 
    }
 
    public ArrayList<VideoModel> getallVideoFromFolder(Context context, String name) {
        SharedPreferences preferences = getSharedPreferences(MY_SORT_PREF, MODE_PRIVATE);
        String sort = preferences.getString("sorting", "sortByDate");
        String order = null;
 
        switch  (sort){
            case "sortByDate":
                order = MediaStore.MediaColumns.DATE_ADDED + " ASC";
                break;
 
            case "sortByName":
                order = MediaStore.MediaColumns.DISPLAY_NAME + " ASC";
                break;
 
            case "sortBySize":
                order = MediaStore.MediaColumns.DATE_ADDED + " DESC";
                break;
        }
        ArrayList<VideoModel> list = new ArrayList<>();
        Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        String[] projection = {
                MediaStore.Video.Media._ID,
                MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.TITLE,
                MediaStore.Video.Media.SIZE,
                MediaStore.Video.Media.HEIGHT,
                MediaStore.Video.Media.DURATION,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
                MediaStore.Video.Media.RESOLUTION
        };
        String selection = MediaStore.Video.Media.DATA + " like?";
        String[] selectionArgs = new String[]{"%" + name + "%"};
 
        Cursor cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, order);
 
        if (cursor != null) {
            while (cursor.moveToNext()) {
 
                String id = cursor.getString(0);
                String path = cursor.getString(1);
                String title = cursor.getString(2);
                int size = cursor.getInt(3);
                String resolution = cursor.getString(4);
                int duration = cursor.getInt(5);
                String disName = cursor.getString(6);
                String bucket_display_name = cursor.getString(7);
                String width_height = cursor.getString(8);
 
                //this method convert 1204 in 1MB
                String human_can_read = null;
                if (size < 1024) {
                    human_can_read = String.format(context.getString(R.string.size_in_b), (double) size);
                } else if (size < Math.pow(1024, 2)) {
                    human_can_read = String.format(context.getString(R.string.size_in_kb), (double) (size / 1024));
                } else if (size < Math.pow(1024, 3)) {
                    human_can_read = String.format(context.getString(R.string.size_in_mb), size / Math.pow(1024, 2));
                } else {
                    human_can_read = String.format(context.getString(R.string.size_in_gb), size / Math.pow(1024, 3));
                }
 
                //this method convert any random video duration like 1331533132 into 1:21:12
                String duration_formatted;
                int sec = (duration / 1000) % 60;
                int min = (duration / (1000 * 60)) % 60;
                int hrs = duration / (1000 * 60 * 60);
 
                if (hrs == 0) {
                    duration_formatted = String.valueOf(min)
                            .concat(":".concat(String.format(Locale.FRANCE, "%02d", sec)));
                } else {
                    duration_formatted = String.valueOf(hrs)
                            .concat(":".concat(String.format(Locale.FRANCE, "%02d", min)
                                    .concat(":".concat(String.format(Locale.FRANCE, "%02d", sec)))));
                }
 
 
                VideoModel files = new VideoModel(id, path, title,
                        human_can_read, resolution, duration_formatted,
                        disName, width_height);
                if (name.endsWith(bucket_display_name))
                    list.add(files);
 
            }
            cursor.close();
        }
 
        return list;
 
 
}
 
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
 
        SharedPreferences.Editor editor = getSharedPreferences(MY_SORT_PREF, MODE_PRIVATE).edit();
        switch (item.getItemId()){
 
            case R.id.sort_dy_date:
                editor.putString("sorting", "sortByDate");
                editor.apply();
                this.recreate();
                break;
 
            case R.id.sort_dy_name:
                editor.putString("sorting", "sortByName");
                editor.apply();
                this.recreate();
                break;
 
            case R.id.sort_dy_size:
                editor.putString("sorting", "sortBySize");
                editor.apply();
                this.recreate();
                break;
 
            case R.id.home:
                onBackPressed();
                break;
 
        }
 
        return super.onOptionsItemSelected(item);
    }
}


package com.armdev.advid.activity;
 
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
 
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GestureDetectorCompat;
 
import com.armdev.advid.R;
 
import static com.armdev.advid.adapter.VideosAdapter.videoFolder;
 
 
 
public class VideoPlayer extends AppCompatActivity implements View.OnTouchListener, ScaleGestureDetector.OnScaleGestureListener, View.OnClickListener {
 
 
 
 
 
 
    RelativeLayout zoomLayout;
    ScaleGestureDetector scaleDetector;
    GestureDetectorCompat gestureDetector;
    private static final float MIN_ZOOM = 1.0f;
    private static final float MAX_ZOOM = 5.0f;
    boolean intLeft, intRight;
    private Display display;
    private Point size;
    int clickCount = 0;
    private Mode mode = Mode.NONE;
    private enum Mode {
        NONE,
        DRAG,
        ZOOM;
    }
    int device_width;
    private int sWidth;
    int screenWidth, screenHeight;
 
 
 
    private boolean isEnable = true;
    private boolean isOpen = true;
    private float scale = 1.0f;
    private float lastScaleFactor = 0f;
    // Where the finger first  touches the screen
    private float startX = 0f;
    private float startY = 0f;
    // How much to translate the canvas
    private float dx = 0f;
    private float dy = 0f;
    private float prevDx = 0f;
    private float prevDy = 0f;
 
    android.view.ViewGroup.LayoutParams lp;
    int position = -1;
    private VideoView videoView;
    private VideoView videoView2;
    LinearLayout one, two , three , four, five, lockControls, unlockControls, rotate, etirer;
    ImageButton goBack, rewind, forward, playPause;
    TextView title, endTime, lockTextOne, lockTextTwo;
    SeekBar videoSeekBar;
 
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction() & MotionEvent.ACTION_MASK){
            case MotionEvent.ACTION_DOWN:
                hideDefaultControls();
                if (scale > MIN_ZOOM) {
                    mode = Mode.DRAG;
                    startX = event.getX() - prevDx;
                    startY = event.getY() - prevDy;
                }
                break;
            case MotionEvent.ACTION_MOVE:
                hideDefaultControls();
                isEnable = false;
                if (mode == Mode.DRAG) {
                    dx = event.getX() - startX;
                    dy = event.getY() - startY;
                }
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                mode = Mode.ZOOM;
                break;
            case MotionEvent.ACTION_POINTER_UP:
                mode = Mode.DRAG;
                break;
            case MotionEvent.ACTION_UP:
                mode = Mode.NONE;
                prevDx = dx;
                prevDy = dy;
                break;
        }
        scaleDetector.onTouchEvent(event);
        gestureDetector.onTouchEvent(event);
        if ((mode == Mode.DRAG && scale >= MIN_ZOOM) || mode == Mode.ZOOM) {
            zoomLayout.requestDisallowInterceptTouchEvent(true);
            float maxDx = (child().getWidth() - (child().getWidth() / scale)) / 2 * scale;
            float maxDy = (child().getHeight() - (child().getHeight() / scale)) / 2 * scale;
            dx = Math.min(Math.max(dx, -maxDx), maxDx);
            dy = Math.min(Math.max(dy, -maxDy), maxDy);
            applyScaleAndTranslation();
        }
        return true;
    }
 
    private void applyScaleAndTranslation(){
        child().setScaleX(scale);
        child().setScaleY(scale);
        child().setTranslationX(dx);
        child().setTranslationY(dy);
    }
 
    private View child(){
        return zoomLayout(0);
    }
 
    private View zoomLayout(int i) {
        return videoView;
    }
 
    @Override
    public boolean onScale(ScaleGestureDetector detector) {
        float scaleFactor = scaleDetector.getScaleFactor();
        if (lastScaleFactor == 0 || (Math.signum(scaleFactor) == Math.signum(lastScaleFactor))) {
            scale *= scaleFactor;
            scale = Math.max(MIN_ZOOM, Math.min(scale, MAX_ZOOM));
            lastScaleFactor = scaleFactor;
        } else {
            lastScaleFactor = 0;
        }
        return true;
    }
 
    @Override
    public boolean onScaleBegin(ScaleGestureDetector detector) {
        return true;
    }
 
    @Override
    public void onScaleEnd(ScaleGestureDetector detector) { }
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);
        /*Assigning Variables*/
        videoView = findViewById(R.id.video_view);
        videoView2 = findViewById(R.id.video_view2);
        one = findViewById(R.id.videoView_one_layout);
        two = findViewById(R.id.videoView_two_layout);
        three = findViewById(R.id.videoView_three_layout);
        four = findViewById(R.id.videoView_four_layout);
        goBack = findViewById(R.id.videoView_go_back);
        title = findViewById(R.id.videoView_title);
        rewind = findViewById(R.id.videoView_rewind);
        playPause = findViewById(R.id.videoView_play_pause_btn);
        forward = findViewById(R.id.videoView_forward);
        endTime = findViewById(R.id.videoView_endtime);
        videoSeekBar = findViewById(R.id.videoView_seekbar);
        lockControls = findViewById(R.id.videoView_lock_screen);
        five = findViewById(R.id.video_five_layout);
        unlockControls = findViewById(R.id.video_five_child_layout);
        lockTextOne = findViewById(R.id.videoView_lock_text);
        lockTextTwo = findViewById(R.id.videoView_lock_text_two);
        rotate = findViewById(R.id.videoView_rotation);
        etirer = findViewById(R.id.videoView_track);
 
 
        /*Adding onClickListener*/
        goBack.setOnClickListener(this);
        rewind.setOnClickListener(this);
        playPause.setOnClickListener(this);
        forward.setOnClickListener(this);
        lockControls.setOnClickListener(this);
        five.setOnClickListener(this);
        unlockControls.setOnClickListener(this);
        rotate.setOnClickListener(this);
        etirer.setOnClickListener(this);
 
        /*getting path and preparing for play video*/
        position = getIntent().getIntExtra("p", -1);
        title.setText(videoFolder.get(position).getTitle());
        String path = videoFolder.get(position).getPath();
        if (path!=null){
            videoView.setVideoPath(path);
            videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
                @Override
                public void onPrepared(MediaPlayer mp) {
                    videoSeekBar.setMax(videoView.getDuration());
                    videoView.start();
 
 
                }
            });
        }else {
            Toast.makeText(this, "path didn't exits", Toast.LENGTH_SHORT).show();
        }
        /*zoom in,out and double tap to go forward,backward
         *  and single tap to hide and show controls */
        zoomLayout = findViewById(R.id.zoom_layout);
        display = getWindowManager().getDefaultDisplay();
        size = new Point();
        display.getSize(size);
        sWidth = size.x;
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        device_width = displayMetrics.widthPixels;
        zoomLayout.setOnTouchListener(this);
        scaleDetector = new ScaleGestureDetector(getApplicationContext(), this);
        gestureDetector = new GestureDetectorCompat(getApplicationContext(), new GestureDetector());
 
 
        setHandler();
        initalizeSeekBars();
 
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) videoView2.getLayoutParams();
        params.width = metrics.widthPixels;
        params.height = metrics.heightPixels;
        params.leftMargin = 0;
        params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
 
        videoView.setLayoutParams(params);
 
        final Handler handler = new Handler(Looper.getMainLooper());
        handler.postDelayed(new Runnable(){
            @Override
            public void run(){
                hideDefaultControls();
            }
        }, 3000);
 
 
 
 
 
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
            public void onCompletion(MediaPlayer mp) {
                videoView.start();
            }
        });
 
 
 
    }
 
 
 
    private void initalizeSeekBars(){
        videoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (videoSeekBar.getId() == R.id.videoView_seekbar) {
                    if (fromUser) {
                        videoView.seekTo(progress);
                        videoView.start();
                        int currentPosition = videoView.getCurrentPosition();
                        endTime.setText("" + convertIntoTime(videoView.getDuration() - currentPosition));
                    }
                }
            }
 
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
 
            }
 
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
 
            }
        });
    }
 
    private String convertIntoTime(int ms){
        String time;
        int x, seconds, minutes, hours;
        x = ms / 1000;
        seconds = x % 60;
        x /= 60;
        minutes = x % 60;
        x /= 60;
        hours = x % 24;
        if (hours != 0)
            time = String.format("%02d", hours) + ":" + String.format("%02d", minutes) + ":" + String.format("%02d", seconds);
        else time = String.format("%02d", minutes) + ":" + String.format("%02d", seconds);
        return time;
    }
 
    private void setHandler(){
        Handler handler = new Handler();
        Runnable runnable = new Runnable(){
            @Override
            public void run(){
                if (videoView.getDuration()>0){
                    int currentPosition = videoView.getCurrentPosition();
                    videoSeekBar.setProgress(currentPosition);
                    endTime.setText(""+convertIntoTime(videoView.getDuration()-currentPosition));
                }
                handler.postDelayed(this,0);
            }
        };
        handler.postDelayed(runnable,500);
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()){
 
            case R.id.videoView_rotation:
                int orientation = getResources().getConfiguration().orientation;
                if (orientation == Configuration.ORIENTATION_PORTRAIT){
                    //set in landscape
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }else if (orientation == Configuration.ORIENTATION_LANDSCAPE){
                    //set in portrait
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
                break;
 
            case R.id.videoView_lock_screen:
                hideDefaultControls();
                five.setVisibility(View.VISIBLE);
                final Handler handler = new Handler(Looper.getMainLooper());
                handler.postDelayed(new Runnable(){
                    @Override
                    public void run(){
                        unlockControls.setVisibility(View.INVISIBLE);
                        lockTextOne.setVisibility(View.INVISIBLE);
                        lockTextTwo.setVisibility(View.INVISIBLE);
                    }
                }, 3000);
                break;
 
            case R.id.video_five_layout:
                if (isOpen){
                    unlockControls.setVisibility(View.INVISIBLE);
                    lockTextOne.setVisibility(View.INVISIBLE);
                    lockTextTwo.setVisibility(View.INVISIBLE);
                    isOpen = false;
                }else {
 
                    unlockControls.setVisibility(View.VISIBLE);
                    lockTextOne.setVisibility(View.VISIBLE);
                    lockTextTwo.setVisibility(View.VISIBLE);
                    final Handler handler2 = new Handler(Looper.getMainLooper());
                    handler2.postDelayed(new Runnable(){
                        @Override
                        public void run(){
 
                            unlockControls.setVisibility(View.INVISIBLE);
                            lockTextOne.setVisibility(View.INVISIBLE);
                            lockTextTwo.setVisibility(View.INVISIBLE);
                            isOpen = false;
                        }
                    }, 3000);
 
 
                }
                break;
 
            case R.id.video_five_child_layout:
                five.setVisibility(View.GONE);
                showDefaultControls();
                final Handler handler2 = new Handler(Looper.getMainLooper());
                handler2.postDelayed(new Runnable(){
                    @Override
                    public void run(){
 
                        hideDefaultControls();
                    }
                }, 3000);
                break;
 
            case R.id.videoView_go_back:
                onBackPressed();
                break;
 
            case R.id.videoView_rewind:
                //1000 = 1sec
                videoView.seekTo(videoView.getCurrentPosition() -10000);
                break;
 
            case R.id.videoView_forward:
                //1000 = 1sec
                videoView.seekTo(videoView.getCurrentPosition() +10000);
                break;
 
            case R.id.videoView_play_pause_btn:
                if (videoView.isPlaying()){
                    videoView.pause();
                    playPause.setImageDrawable(getResources().getDrawable(R.drawable.ic_baseline_play_arrow_24));
                }else {
                    videoView.start();
                    playPause.setImageDrawable(getResources().getDrawable(R.drawable.netflix_pause_button));
                }
                break;
 
            case R.id.videoView_track:
 
                DisplayMetrics metrics1 = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metrics1);
                android.widget.RelativeLayout.LayoutParams initialParams = (android.widget.RelativeLayout.LayoutParams) videoView.getLayoutParams();
 
                if (clickCount==1){
                    initialParams.alignWithParent = true;
                    videoView.setLayoutParams(initialParams);
                    clickCount=0;
                }
                else if (clickCount==0){
                    DisplayMetrics metrics = new DisplayMetrics();
                    getWindowManager().getDefaultDisplay().getMetrics(metrics);
                    android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) videoView2.getLayoutParams();
                    params.width = metrics.widthPixels;
                    params.height = metrics.heightPixels;
                    params.leftMargin = 0;
                    params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
 
                    videoView.setLayoutParams(params);
                    clickCount=1;
                }
                break;
        }
    }
 
    public void getDeviceWidthAndHeight(){
        lp = videoView.getLayoutParams();
        screenWidth = getWindowManager().getDefaultDisplay().getWidth();
        screenHeight = getWindowManager().getDefaultDisplay().getHeight();
 
    }
 
    private class GestureDetector extends android.view.GestureDetector.SimpleOnGestureListener{
 
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (isEnable){
                hideDefaultControls();
                isEnable = false;
            }else {
                showDefaultControls();
                isEnable = true;
                final Handler handler = new Handler(Looper.getMainLooper());
                handler.postDelayed(new Runnable(){
                    @Override
                    public void run(){
                        hideDefaultControls();
                    }
                }, 3000);
            }
            return super.onSingleTapConfirmed(e);
        }
 
        @Override
        public boolean onDoubleTap(MotionEvent event) {
            if (event.getX() < (sWidth / 2)) {
                intLeft = true;
                intRight = false;
                videoView.seekTo(videoView.getCurrentPosition() - 20000);
                Toast.makeText(VideoPlayer.this, "-20sec", Toast.LENGTH_SHORT).show();
            } else if (event.getX() > (sWidth / 2)) {
                intLeft = false;
                intRight = true;
                videoView.seekTo(videoView.getCurrentPosition() + 20000);
                Toast.makeText(VideoPlayer.this, "+20sec", Toast.LENGTH_SHORT).show();
            }
            return super.onDoubleTap(event);
        }
 
 
    }
 
    private void hideDefaultControls(){
        one.setVisibility(View.GONE);
        two.setVisibility(View.GONE);
        three.setVisibility(View.GONE);
        four.setVisibility(View.GONE);
        //Todo this function will hide status and navigation when we click on screen
        final Window window = this.getWindow();
        if (window == null){
            return;
        }
        window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        final View decorView = window.getDecorView();
        if (decorView!=null){
            int uiOption = decorView.getSystemUiVisibility();
            if (Build.VERSION.SDK_INT >= 14) {
                uiOption |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
            }
            if (Build.VERSION.SDK_INT >= 16) {
                uiOption |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            }
            if (Build.VERSION.SDK_INT >= 19) {
                uiOption |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            }
            decorView.setSystemUiVisibility(uiOption);
        }
    }
 
    private void showDefaultControls(){
        one.setVisibility(View.VISIBLE);
        two.setVisibility(View.VISIBLE);
        three.setVisibility(View.VISIBLE);
        four.setVisibility(View.VISIBLE);
        //todo this function will show status and navigation when we click on screen
        final Window window = this.getWindow();
        if (window == null){
            return;
        }
        window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        final View decorView = window.getDecorView();
        if (decorView!=null){
            int uiOption = decorView.getSystemUiVisibility();
            if (Build.VERSION.SDK_INT >= 14) {
                uiOption &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
            }
            if (Build.VERSION.SDK_INT >= 16) {
                uiOption &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            }
            if (Build.VERSION.SDK_INT >= 19) {
                uiOption &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            }
            decorView.setSystemUiVisibility(uiOption);
        }
    }
 
    @Override
    public void onBackPressed(){
        super.onBackPressed();
    }
}


Configuration: Windows / Chrome 91.0.4472.164

1 réponse

Messages postés
15087
Date d'inscription
lundi 11 juillet 2005
Statut
Modérateur
Dernière intervention
21 juillet 2021
3 492
Hello,

Quel est le problème exactement ? Il te suffit juste de reinitialiser ton player avec ta nouvelle video à la fin de chaque lecture, non ?
Salut,
je ne sais pas trop comment mais j'ai réussi hehe
Merci de ton aide !

Voila mon code pour les curieux

 private void prochaineVid(){
        videoView.start();
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
            public void onCompletion(MediaPlayer mp) {
                if (index < VideosAdapter.videoFolder.size()){
                    position = getIntent().getIntExtra("p", -1);
                    String path2 = VideosAdapter.videoFolder.get(position + index).getPath();

                    videoView.setVideoPath(path2);
                    prochaineVid();

                    index ++;
                }else{
                    index = index - VideosAdapter.videoFolder.size() ;
                    position = getIntent().getIntExtra("p", -1);
                    String path2 = VideosAdapter.videoFolder.get(position + index).getPath();
                    index ++;
                    videoView.setVideoPath(path2);
                    prochaineVid();

                }