Unable to play this video error

    public class MainActivity extends AppCompatActivity {
    Button clk;
    VideoView videov;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    clk=(Button) findViewById(R.id.video);
    videov=(VideoView)findViewById(R.id.videoView);
    }

    public void videoplay(View v){
   String videopath = "android.resource://"+getPackageName()+"+R.raw.movie";
    Uri uri =Uri.parse(videopath);
    videov.setVideoURI(uri);
    videov.requestFocus();
    videov.start();

    }
    }

Unable to play this video error ... !! see image Screen shot What to do? After clicking the play button, he says that I can’t play this video. !! Need to solve this problem.

+1
source share
1 answer

Hi, the day before yesterday I had the same problem and I tried almost everything, but did not get any success. After that I used this library and it works great. Just follow a few steps:

Step 1. Add it to your gradle

compile "fm.jiecao:jiecaovideoplayer:4.7.0"

Step 2. Add it as xml video playback.

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

3. , ,

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();
}
}

. , . . . .

:

- URL-, , .

:

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

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

, .

+1

Source: https://habr.com/ru/post/1655603/


All Articles