I want to build an app which will allow to view online video and to cache it.
But I need help with this: when user hits the magic "Play" button I want to start downloading video on external storage and to play it at the same time. How do I manage the whole process? What callbacks of MediaPlayer should I use? Any hints?
Looking my projects:
https://github.com/master255/ImmortalPlayer One thread to read, send and save to cache data. Most simplest way and most fastest work. Complex logic - best way!
https://github.com/master255/VideoViewCache Simple Videoview with cache. Two threads for play and save data. Bad logic, but if you need then use this.
Related
I am using the CameraX api approach to record the videos and saving them as explained in the documents: https://developer.android.com/training/camerax/video-capture
I tried with ffmpeg-android-java but clearly it needs to process the saved video not adding to the saved frames in real time.
Now, I want to add a watermark to all saved videos in easy and not costly way and without the need to reprocess the video?
Also, if there is no way, what the best and fastest approach to process the video to only add a watermark?
My suggestion is that you need to write a player-like code that uses opengles to draw videos so you can add your own arbitrary watermark. Or use the cross-compiled ffmepg dynamic library (or static library) to add your own filters.
I shared an example of cross-compiled ffmpeg on github. Is to implement a player that can play video. Check it out here.
I hope you got some help.
I am developing a soundboard application in which I need to get the specified audio file from the server when the user requests it, but I don't want to stream it or download it every time, just the first time so I was thinking of caching it someway.
I made some research and I found the ExoPlayer library from google but I think it's kinda overkill for my purpose and I can't seem to get my head around it as I'm not so experienced in android development.
Is there any library that I can use?
If not, how can I make the process myself?
Save it to the file system the first time. Then you never have to download it again.
Can we reset all the values that hold in mediaRecorder while recording video?
I've tried just using mediaRecorder.reset() while recording video. But it won't work. I don't know is it possible or not. If it is possible please any references will appreciate.
I've read this and also google developers, mediaRecorder in developers. But any of references didn't mention my issue.
EDIT :
What I want is while recording a video set mediaRecorder.reset() and mediaRecorder.start(). The problem occurs when I'm doing this. I need to chunk of video clips while recording the same video. Need those process in parallel. While I'm trying to stop and restart the camera capturing methods it will miss many frames. Bcoz handling camera is somewhat cost for the processor. I tried this and it occurs some errors that telling session configuration failed. Now I'm stuck in here. Need help!
Thank you for your valuable time.
Edit in response to clarifications:
Ok, so you want to split the video file into multiple separate files.
You'll need to use the lower-level APIs (MediaCodec, MediaMuxer) to implement this yourself; the higher-level MediaRecorder does not support this without losing frames.
Original:
So you're trying to pause the video recording temporarily.
Unfortunately, there's no support for this before API level 24, which added MediaRecorder.pause(). You can't call MediaRecorder.reset() mid-video and have it work.
All you can really do is to record the full video and then post-process it to crop sections you don't want.
My app shows images to user one after one. The images are downloaded from server. As I do not want the user to wait for the images to be downloaded I cached those in a local file system (say new 50 images) .
Implementation:
from onCreate method start a AsyncTask that will keep in downloading images in background.
Is AsyncTask best for this use case?I do not want to use a Service as I do not want the download to happen continuously
Is AsyncTask best for this purpose?
I would suggest using an existing library, such as Picasso (by Square) or Volley (by Google).
Picasso is especially easy to implement and will work excellently for your purpose, and is as easy as:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
You won't have to concern yourself with AsyncTasks or AsyncTaskLoaders as the library takes all of this out of your hands, caching both images in memory and on the disk.
If you insist on building your own solution, I suggest looking around for related questions as there are many things to bear in mind:
AsyncTasks may be ill fitted as they are directly coupled with a single activity; you'll need a Loader or a mechanism similar to Loaders to deliver results to whichever activity wants an image.
On older devices, bitmaps reside in a special region of memory that isn't managed by the GC; you'll have to dispose of bitmaps manually when you're done with them.
Bitmaps use a significant amount of memory and need to be carefully managed to avoid OOMEs, such as downsampling them when loading and storing in memory inside an LruCache.
Beware of managing the size of the image cache directory when writing images to disk.
Yes, you can use Asynctask for this purpose. And using one of the apis of Asynctask "onProgressUpdate(), you can in parallel update the UI as your images are getting downloaded.
you can use universalImageLoader library for downloading images in an efficient way.
see this how to use universal Image loader for downloading images
One more solution for your requirement is Volley Library
I'm new to the android development, and programming in general.
I'm developing app to create football statistics for each player, and in the long run I'm using SQLite to store data. However I was wondering if there is a way and if it will make sense, to store data during the run of my application without inserting it to the db, every time user is trying to add new statistics.
Also I'm wondering if there is a point in doing that, my biggest concern is that inserting data to a db all the time will slow down my app, and I would appreciate what more experienced developers do know, and think about this 'issue'
I was trying to research the topic, however all I got was storing data in db, and using SharedPreferences and I don't think that's what I'm looking for, however I can be wrong.
please help.
SQlite is what you're looking for. SharedPreferences are for just that - preferences, not large amounts of stats.
Put your database code in a separate thread and you won't notice any slow down in your app. Ask back here for help on this.
I can't speak to android directly but I have faced similar design issues on iPhone and desktop applications.
It depends on the specifics of the application as to what would be the best way. If your app is mostly about entering plays and saving statistics, I would keep a small set of the latest statistics in memory enough to populate the user interface and then create a "data manager" running on a background thread whose sole purpose was to insert these newly added statistics to the database.
Honestly, I would put it in the DB immediately. With the way android works, if your user navigates to another app (or possibly even receives a phone call) the data they have already entered could be lost.
It is possible to cover that contingency obviously (saving in onPause, etc.), but I've always felt it was safer to get the data into permanent storage as soon as possible. (Note this is a hotly debated topic, I'm merely stating my preference).
Saving to the DB immediately doesn't affect app speed (depending on how much of what type of data you are inserting) so much as battery life. Accessing permanent storage takes more in terms of power as there are several more steps the processor needs to take.
If you do all your DB activities in a thread other than the UI thread the transactions will be almost completely unnoticable in terms of app speed.
If you use implement Loader callbacks it should not slow your application down. Have a look at the Loader classes. They are available through the Android compatibility library.