20

I can play a video from the Internet by inserting the URL like below:

mPath   = Uri.parse("http://commonsware.com/misc/test2.3gp");
mVid.setVideoURI(mPath);
mVid.requestFocus();
mVid.start();

But now I have a video in my raw folder so the path is res/raw/testing.3gp. The code below doesn't work, and I've tried some other ways too to no avail.

mPath   = Uri.parse("../../res/raw/testing.3gp");

Any suggestions?

taraloca
  • 9,077
  • 9
  • 44
  • 77
  • 1
    okay...I found the code that I had working before with different video, but it is not working now. mPath = Uri.parse("android:resource://com.example.wordweather/" + R.raw.scott); – taraloca Aug 31 '10 at 13:02
  • Possible duplicate of [How to play videos in android from assets folder or raw folder?](http://stackoverflow.com/questions/3028717/how-to-play-videos-in-android-from-assets-folder-or-raw-folder) – Ciro Santilli OurBigBook.com Feb 03 '16 at 20:37

4 Answers4

33

I had the same problem. This worked for me:

Uri video = Uri.parse("android.resource://com.pac.myapp/raw/master");

So as you see you have 3 parts of the uri:

  1. android.resource://
  2. com.pac.myapp
  3. /raw/master

master is the name of your video

Twenty
  • 5,234
  • 4
  • 32
  • 67
Alex Bush
  • 735
  • 1
  • 13
  • 26
  • I wish I could mark this as the correct answer. This helped me so much!! Thank you. – dfetter88 Jan 05 '11 at 14:31
  • 13
    That didn't work for me.. I got the dreaded 'this video could not be played error'. What did work however was Uri url = Uri.parse("android.resource://com.calvium.myApp/" + R.raw.video); (where my video resource was called 'video.3gp'. – Ben Clayton Feb 16 '11 at 16:09
  • This solution worked for me. However, I'm suspicious about it working on any other OS versions/devices - i.e. there's been loads of people who reported the "R.raw.*" version to be working instead. Can anyone elaborate as to what one could expect from VideoView? – JakeP Jul 23 '14 at 15:35
  • More on this topic. http://javatech.org/2011/01/discovering-android-embedding-video-in-an-android-application/ – bickster Mar 06 '15 at 22:35
6

this works for me

 String videoName = nameWithoutFileExtention;

 int id = getResources().getIdentifier(videoName, "raw", getActivity().getPackageName());

 final String path = "android.resource://" + getActivity().getPackageName() + "/" + id;

 vvBgVideo.setVideoURI(Uri.parse(path));
3akat
  • 164
  • 2
  • 6
0
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn=(Button)this.findViewById(R.id.playvideo);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                VideoView vid=(VideoView)findViewById(R.id.video);
                vid.setMediaController(new MediaController(MainActivity.this));
                Uri video = Uri.parse("android.resource://com.example.tenzinthinley.video/raw/ed");
                vid.setVideoURI(video);
                vid.requestFocus();
                vid.start();
            }
        });
    }
}

Change my name if this doesn't works. 'ed' is the video file name.

Shreyash S Sarnayak
  • 2,309
  • 19
  • 23
-1

You just need to locate song in raw folder under resource folder. if it is link then

 private String urlVideo ="http://www.pocketjourney.com/downloads/pj/video/famous.3gp";

    //Make uri from song located in raw folder
        Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"
                + R.raw.shakebooty);
        player.setUpVideoFrom(uri.toString());

        public void setUpVideoFrom(String source) throws IllegalArgumentException,
                IllegalStateException, IOException {

            mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

//Only to check if you want to play song from url
            if (source.contains("http"))
            {
            mPlayer.setDataSource(source);
            }
//If want to play song from uri you created from song in raw folder
        else {
             mPlayer.setDataSource(ctx, source);
             }

        }

Enjoy playing video in surface view

DeepakPanwar
  • 1,389
  • 14
  • 22