Android VideoView Update Subtitles - android

I'm trying to make a video player with VideoView that supports subtitles using a TextView on top of it.
I've already parsed the subtitles but now i need an event that runs every time a frame changes or so to update the subtitles with the current playing position.
I tried making a thread but I am not able to change my TextView in that separate thread. Is there an event on VideoView/MediaPlayer that runs every frame change that I can override to call my updateSubtitle method?

Starting with Android 4.4 , you can put subtitles from within the VideoView itself:
https://www.youtube.com/watch?v=hCRGc2PcmB8#t=130

Coming to your first question, there is no event that happens each video frame. Having said that there are ways of getting current time and synchronize subtitles to the current time. Below links might be of help
A white paper on how to support subtitles in Android

Related

VideoView on RecyclerView

I'm developing a social media app which has feed tab based on RecyclerView. On that feed tab I have many types of feedtype like text, photo, photo and text, book, etc... So till now I didn't had any problem about this. On my view holder I've Middle Item Container Panel. I'm putting template which is coming from my feedtypemanager class. So now I need to add videoview for my video feeds. First problem is I'm using rtsp server for streaming. VideoView starting after 15 seconds from seeing that view. Second one is when I scroll down and come up again my VideoView starting from beginnging and I'm waiting 15 seconds again to play that video. So how can I do that view like Instagram fast ? Which protocol I should use and Which VideoPlayer ? Thanks for help.
I've faced the same issues with videoview,
I would recommend to use Exomedia library and make your life easy with that.
For smooth video playback use some caching mechanism.
I would recommend AndroidVideoCache Library.
Use app:useTextureViewBacking="true" for smooth animations and transitions of videoview.

Run media file in CardView layout

Is there a way to have a media file (audio/video) running in a cardview layout? I want to have a video preview of the file inside a card layout, when the user clicks on the card the video/audio is taken fullscreen and played, just like Facebook's feed.
In order to get that kind of functionality you have to solve a few problems:
You cannot use VideoView in a list because it is extending SurfaceView, and if playback is on and user starts scrolling, the visual effect will look like video is trying to catch the scroll. So you need a special VideoView that is based on something else, for example TextureView.
Managing video player state:
in order to start/stop playback we need to call a few methods of MediaPlayer.class:
setDataSource()
prepare()
start()
stop()
reset()
release()
These methods are direct calls to hardware and it may take some time before hardware will respond. So we cannot call it in UI thread. It will block it for more than 16 milliseconds, so user will see a lagging scrolled list. We have to call it from a background thread.
You need to track in run time which view on the screen is active and this view should be playing.
I've created an opensource project called VideoPlayerManager.
It is thoroughly documented and some basic flows are handled in the demo application. It is not ready for production but if you need some reference of how to get this kind of functionality, you can find it there.
P.S. Regarding CardView: it is a regular view. You can put a video player into it and get video playback in CardView.

Play video in Android listview

I am trying to play videos in my listview just like Vine or Instgram. I have been trying to use TextureView with a media player except that when attaching TextureView to the media player I experience issues where the textureview is not being reused properly by the GetView method. The textureview renders some old incorrect videos when scrolling down in my list.
Does anyone know how to play videos in ListViews (Not using VideoView!!!)??
Just wanna give you advice.
You can use WebView inside listview item and using javascript to play the video. you can find the javascript play on html
http://www.w3schools.com/tags/av_prop_autoplay.asp
I hope my advice may help you something out.
Found the solution to this problem. I need to use TexutreView with MediaPlayer, and I need to dynamically add the TextureView to each item in the list. I also need to make sure that I remove any previous TexutreViews that was previously attached to the item in the list before adding a new one dynamically. Also, I need to make sure that I only play one MediaPlayer at a time in the listview to avoid causing any strange behaviors (i.e. videos can play in the wrong position).
You really need to use TextureView. There is actually few problems you need to solve.
Please find expanded answer here:
Run media file in CardView layout

View pager and Playing Video on android

I have a viewpager which has two views in it. On the first view I have a list of videos and on the other one I play the video.
The issue is when I play the video on the second view and if I want to go back to the first view, there is a black rectangle remaining from the video. it disappears after a few seconds.
I am using a galaxy note running ICS.
Can it be because of memory usage?
Thanks,
I solved this problem long time ago by setting background color of the videoview to some color and then making it '0' onVideoPrepared().
Well, do you "stop()" the video when you start dragging the page ?
if not, then you need to add a OnPageChangeListener to the viewpager, so when you start scrolling/dragging the page, you stop the videoview, that should fix your problem,
the more probable thing is that for optimization reasons does not want to be playing the video as dragging the page so puts a "picture" of the video while moving.

Create custom media player like Youtube in Android

I have to create media player like youtube player.Actually if i use VideoView for play video and MediaController for controll video(MediaController onlyu provides play,pause,next,pre and seek options).But in my player i have to add one more option i.e bandwidth(I would have three bandwidth and on clicking on bandwidth video will play).So please suggest me.
As far I know, MediaController doesn't give many opportunities to be customized. So, you have two options depending on your UI requirements and the effort you are willing to do.
The hard way: You can just get rid of Android MediaController and
implement your own media controller, since you are not bound to use
it. MediaPlayer (through VideoView) provides you the needed
functions to build it: pause(), play(), resume() methods and event
listeners like onPrepared, onStopped, etc. To display the progress
bar you can use SeekBar, but you will have to code the interaction
with MediaPlayer (this is, the progress bar will not move alone).
The easy way: you can find another place to put your bandwith
button, for instance, on the top of the screen. You might even place
your button over MediaController.
You just have to create a layout properly combining the GUI elements you need. VideoView can be used with other GUI elements like buttons and can be nested within layouts like RelativeLayout and LinearLayout.
So, if you want your bandwidth button adjacent to VideoView, you may use LinearLayout, if you want your bandwith button over the video surface, like MediaController, you may use RelativeLayout, managing properly the layers.
have a look at SurfaceView, that will give you an idea on not bounding your logic with player.

Categories

Resources