Can't play this video error

前端 未结 1 1738
野的像风
野的像风 2021-01-24 04:25
    public class MainActivity extends AppCompatActivity {
    Button clk;
    VideoView videov;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
          


        
相关标签:
1条回答
  • 2021-01-24 05:08

    Hi day before yesterday i had same problem and tried almost everything but didn't get any success. After that i used this library and it work fine. Just follow few steps:

    Step1. Add it to your gradle

    compile "fm.jiecao:jiecaovideoplayer:4.7.0"
    

    Step2. Add it as your video play in xml layout.

    <fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
        android:id="@+id/videoPlayer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

    Step 3. Check from here how to use this library in your class,

    public class PlayVideoActivity extends BaseActivity {
    
    @BindView(R.id.videoPlayer)
    JCVideoPlayerStandard mVideoPlayer;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        restoreFromIntent(getIntent());
    }
    
    @Override
    public int getLayout() {
        return R.layout.activity_play_video;
    }
    
    //create intent for this activity with all the necessary params
    public static Intent createIntent(Context context, String videoUrl) {
        Intent intent = new Intent(context, PlayVideoActivity.class);
        intent.putExtra(ValueConstants.VIDEO_URL, videoUrl);
        return intent;
    }
    
    // get video path from intent and play the video here
    private void restoreFromIntent(Intent intent) {
        String videoPath = intent.getExtras().getString(ValueConstants.VIDEO_URL);
        mVideoPlayer.setUp(videoPath
                , JCVideoPlayerStandard.SCREEN_LAYOUT_LIST, "");
    }
    
    @Override
    public void onBackPressed() {
        if (JCVideoPlayer.backPress()) {
            return;
        }
        super.onBackPressed();
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        JCVideoPlayer.releaseAllVideos();
    }
    }
    

    One more bonus thing from my side. You can do video cache also by using this library. Yesterday i found this also.One time play from internet.After it play without internet also.

    Updated answer:

    Above example i have provided for playing online videos from url but this question have problem related to video path problem.

    Just Changed this path:

    String videopath = "android.resource://"+getPackageName()+"+R.raw.movie";
    Uri uri =Uri.parse(videopath);
    

    To this,

    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.yourvideo);
    

    Thanks hope this will help you.

    0 讨论(0)
提交回复
热议问题