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 Build a Self-Destructing Message Android App Sending Messages Sending the Message

Shariq Shaikh
Shariq Shaikh
13,945 Points

When attempting to send a video message using "Take video" error occurs but not when I use "Choose video"

So when testing out the app I first try to send a video message using the "Take Video" option I get the "something is wrong with the file" message. But when I select "Choose Video" I am able to send the same video with no problem. Also I get this error message in logcat every time I attempt to send a video message using the "Take Video" option:

11-03 22:52:21.654 7508-7508/com.example.shariq.ribbit E/FileHelper๏น• /storage/emulated/0/Pictures/Ribbit/VID_20141103_225208.mp4: open failed: ENOENT (No such file or directory)

Shariq Shaikh
Shariq Shaikh
13,945 Points

ps: I'm testing on my htc one and I copied and pasted code for main activity and recipient activity directly from the project files

Harry James
Harry James
14,780 Points

Hello Shariq!

So, I understand you have copied and pasted the default code for MainActivity and RecipientActivity and are still having this problem. Do you see the Toast message "There was a problem accessing your device's external storage." when you try to Take a Video? If so, there seems to be a problem setting the storage directory for your videos.

Let me know if this is the issue or not and I'll work through trying to fix it with you.

Hope I can help!

Shariq Shaikh
Shariq Shaikh
13,945 Points

There is no Toast message, and it's really weird because it saves the video file allowing me to send the video using the choose video option with no problems. At this point I have copied and pasted all the java files from the available project files just to be safe. Everything else(with the exception of one other bug which I'll save for a different forum post) works flawlessly. I'm guessing it is either the device I'm using or there's something wrong in the project files. Do you think it could be something I'm doing or something else? I'm gonna try using the emulator and see what happens

Harry James
Harry James
14,780 Points

It looks like what's happening is somewhere in your code it's trying to open the file at /storage/emulated/0/Pictures/Ribbit/VID_20141103_225208.mp4.

So, are you now using the exact project files and still are having this issue?

If so, do give the emulator a go and let me know if anything changes.

1 Answer

I had the same problem and figured out it has to do with certain Android devices, one of which is the htc one. On these devices with the code we wrote, when taking photos and videos these files are stored in the DCIM directory. While photos are stored in the Ribbit folder we created as well (which is another issue as the user will have 2 copies of the same image on their device), the videos are not stored in the Ribbit folder. Therefore the Uri we created (that points to the Ribbit folder) is incorrect, and the message will be null, and you will see that error. Here is the fix I came up with which involves changing how you get the Uri for your takeVideoIntent in MainActivity. Use the following for the case where we take the video:

                    //Take Video
                    case 1:
                    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); //leave this line alone
                    //Change the next line to get your Uri like this:
                    mMediaUri = getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 
                    new ContentValues());

instead of:

                   mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);

This stores your videos in the 'video' directory on your device instead of the 'picture' directory and it won't store a duplicate video in the DCIM folder. Now when createMessage() is called it will have the appropriate Uri so fileBytes won't be null and your message should send without the error. The downside of this approach is since we no longer call getOutputMediaFileUri() when it comes to taking videos, we're no longer saving the file the way we specified in this method, with our timestamp, in the Ribbit directory, etc. If anyone has a better solution I'm all ears!

Harry James
Harry James
14,780 Points

Hmm... that's interesting. Wasn't aware of this happening on certain phones.

This is a perfectly reasonable way to go about this and there are a few ways of saving these files. I would recommend it other some other options (Copying and pasting files from locations, plaagh) as that wouldn't be very good and would cause unnecessary performance problems.


A better alternative to what I said above (Which I'm not saying is better than what you said as it's not - it depends on how you want the images to be stored after uninstallation of the app) would be to pass an EXTRA_OUTPUT to the camera app:

intent.putExtra(MediaStore.EXTRA_OUTPUT, uriOfOutput);

This would allow you to store the file wherever you want however, always be aware of the risk that not all apps take every intent into account (I have found this out myself as my Cyanogen Camera didn't (And maybe still doesn't) count down the maximum time of a video which could be a slight flaw as it enables users to upload a video of any length to Parse). Therefore, the safest method would be what you have talked about above.


Anyhow, thanks for the heads up to everyone! Glad to hear that you were able to investigate it and come up with your own solution :)