Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Shariq Shaikh13,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)
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());
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!