Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Attaching videos in my android app!

In my app I need to attach videos! There are 9 individual videos. They need to be hosted locally on the device. The app must not be dependent on an internet connection. HOW DO I DO THIS.

1 Answer

The 'Media Playback' section of the Android documentation has a good overview of this, but here's the gist of it from the Android docs:

In your project, you can put files under your 'res' directory in a package named 'raw'. Then access and play your media files like so:

MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.media_file_1);
mediaPlayer.start(); // no need to call prepare(); create() does that for you

I haven't tried this specifically with video files but I believe it should work basically the same. That should at least get a video playing. Let us know if you have trouble with it. From there the link above has more details.

The 'File Storage' section of the 'Android Data Persistence' lesson is a good resource to become familiar with this type of thing. What he does is slightly different but serves as a good lesson to become familiar with the general concepts involved in working with data in android.

Good luck!