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
ugochi douglas
Courses Plus Student 51 Pointsparse file
i want to be able to open my parse file(which is a song or video) in my app, not hand it over to the phone, how do i go about doing this please?
4 Answers
Harry James
14,780 PointsHey ugochi douglas!
I'm not sure what you mean by this so, I will discuss two possible options here.
Option 1 - Download to the app.
This will download the file to the phone but, it won't be accessible to the user in their normal libraries. They would need to use the likes of a file browser to view the file.
The Parse documentation offers a really simple guide on how to do this here
As you can see, you can save and retrieve files in just a few lines of code (It tends to be the callbacks that take more code but, they'll have an autocomplete option to save you that worry).
Once the file has been downloaded to the apps folders, you can then use intents or similar to display the media. After the media has been displayed, you can then delete the file.
Note that deletion does not mean that the file is completely inaccessible - It will be to the average user but hackers can still recover deleted files or, stop access to the app to prevent the code that deletes the file from being run. Also, if the app was to crash when returning from an intent, this would mean that the deletion code would not run and therefore, the file would be kept on the device (But still hidden unless using a File Browser).
Option 2 - View on the web.
This won't exactly download the file to the phone however, it may still be accessible through cache. Also, this doesn't mean that users will never be able to download the file as, there would probably be an option through some browsers to download the media file. Also, a user could screengrab the media and therefore be able to keep it.
You can use the getUrl() method from a ParseFile object to get the URL of that object as shown here.
To make a media file accessible to view but not to download is a very hard thing to do. It would require you to stream the media through some medium though, even then a screen recorder/screenshot could be used.
Hope it helps and, if you have any more questions, give me a shout! :)
ugochi douglas
Courses Plus Student 51 Pointsthanks...my question is more of how to stream the video or music in my app
Harry James
14,780 PointsThat is a lot more difficult - Android doesn't use Flash so, that rules that out.
If you are going to go that route, I would recommend you use something other than Parse. Parse does not offer a built-in streaming functionality so, you would perhaps have to find somewhere developer-friendly that would have an API to upload a video and stream it to the user.
I don't know of any services that offer this functionality so, I will have to leave you to do the research for this.
ugochi douglas
Courses Plus Student 51 Pointsso..i can't like....get the video and put it in the video view?
Harry James
14,780 PointsYou can sort of stream it through a MediaPlayer (MediaPlayer's are recommended over VideoView's) but, note that this would be fine for a normal person but a rooted user could use a network hack also to see where the app is getting the file from. There is no real easy way of getting around this though so, I wouldn't worry about it.
It's still quite complicated to set up a MediaPlayer and, chances are you'll have a lot of errors on the way! You can get the media URI to the web address though and make a callback (Use an onPreparedListener()) so that once the media has been fully downloaded, you can run mediaPlayer.start().
If you do run into any trouble on the way with MediaPlayer's, do check out the documentation or give me a shout on these forums.
Hope it helps! :)
ugochi douglas
Courses Plus Student 51 Pointswould any of these examples help?? (http://www.androidbegin.com/tutorial/android-video-streaming-videoview-tutorial/) or this (http://code.tutsplus.com/tutorials/streaming-video-in-android-apps--cms-19888)
Harry James
14,780 PointsThem examples look fine - try them out for yourself and see what best suits your needs :)
ugochi douglas
Courses Plus Student 51 Pointsthey work well....but with a URL...how do i put the uri for the video into it.....i just tried looking for an open source like picasso to help with that...that's if it exists and i just saw this one (https://kickflip.io/blog/kickflip-live-mobile-video-streaming-sdk/)
Harry James
14,780 PointsOooh! That site looks nice!
You can either use that site and follow the SDK guide or use Android's built in assigning of a URI. The method to use is VideoView.setVideoURI(Uri uri) (Click for more details).
I would however, recommend that site you just provided if it doesn't have limitations. Using a third-party API is fantastic because then other people have worked on it (usually for a long period of time) perfecting it and, it saves us having to write code!
Obviously, it is up to you which path you want to take and I say, why not try them both? Test them out and see what they're like before picking your final provider of streaming video. If you're going to be using them throughout your app, it's definitely worth trying them both before you start using the same one throughout.
Hope it helps :)
ugochi douglas
Courses Plus Student 51 Pointsthanks alot...i used the VideoView.setVideoURI(Uri uri) and it works for mp3 atleast...still trying the rest....but would love to show image when its a music file on th screen of the video view...do you have an idea on how to? and please try to help me here......thanks again.
ugochi douglas
Courses Plus Student 51 Pointsugochi douglas
Courses Plus Student 51 Pointsthanks...my question is more of how to stream the video or music in my app
ugochi douglas
Courses Plus Student 51 Pointsugochi douglas
Courses Plus Student 51 Pointsthanks...my question is more of how to stream the video or music in my app