Can't play mp4 video in my Android app

后端 未结 3 665
春和景丽
春和景丽 2021-02-04 21:21

I very want to play mp4 video in my android app. I even wrote a bit of code for it:

String sourceUrl = \"http://tvstream.cn.ru/storage/1kanal/20120530/\"
                


        
相关标签:
3条回答
  • 2021-02-04 21:39

    Probably your file is using an unsupported profile, notice that official media formats page only lists Baseline Profile as supported for H.264 AVC.

    Try transcoding the video specifying Baseline Profile as suggested in this stackoverflow question, i.e. if your container is MP4 run:

    ffmpeg -i yourfile.mp4 -c:v libx264 -profile:v baseline -level 1 yourfile_BaselineProfile.mp4
    

    If this works it's not a issue in your code, you just have to use supported formats.

    0 讨论(0)
  • 2021-02-04 21:50

    VideoView classes does not allow playing MP4 file format videos. Please go through this link for Android Media Formats. Try checking your video with Daroon Player

    0 讨论(0)
  • 2021-02-04 21:53

    Try this

    File clip=new File(Environment.getExternalStorageDirectory(),
                           "test.mp4");
    
        if (clip.exists()) {
          video=(VideoView)findViewById(R.id.video);
          video.setVideoPath(clip.getAbsolutePath());
    
          ctlr=new MediaController(this);
          ctlr.setMediaPlayer(video);
          video.setMediaController(ctlr);
          video.requestFocus();
          video.start();
    
    0 讨论(0)
提交回复
热议问题