getDuration function in mediaplayer android - android

I'm developing android application using Mediaplayer class that plays a song using a url. The problem is that the returned value after calling
mp.getDuration()
is larger than the actual duration of the song.
for example the song has a duration of 4.3 but in my application it gives that it equals 4.6

Can you give more details about your working environment (android version, file format, ...)?
The MediaPlayer is quite buggy. Surely you are experiencing one bug regarding some specific format. Have a look to the open issues in this topic.

Related

ExoPlayer playing currently recording media files

Let me refraise my question, I wrote it in a hurry.
Current situation:
I have set up a digital video recorder to record broadcasts provided via DVB-C. It is running on a raspberry 3B using TVHeadend and jetty/cling to provide UPnP and other possibilities to access media files. For watching recordings, I wrote an android player app using IJKPlayer, which runs on smartphones, FireTV and AndroidTV.
One hassle when playing media files which are currently beeing recorded is, that IJKPlayer doesn not support timeshifting. Means, when I start playing a currently recording file, I can only watch the length which is known by the player at that moment. Anything which is recorded afterwards can not be played. I need to exit the player activity and start it again. I have resolved that issue by "simulating" a completed recoding using a custom servlet implementation. Since the complete length of the recording is already known, I can use ffmpeg to accomplish this.
Future situation:
I plan to move away from IJKPlayer to ExoPlayer, because it supports hardware playback and is much faster when playing h.264 media. I can of course use the same solution like above, but as far as I have found out yet, ExoPlayer can support media files which are currently being recorded by using the Timeline class. However, I don't seem to find neither a usefull documentation nor any good example. Hence, I would appreciate any help with the timeline object.
Regards
Harry
Looks like my approach won't work. At least, I didn't find a solution. Problem is, that the server returns the stream size as it is during player-start-time. I didn't find a method to update the media duration for "regular" files.
However, I can solve the problem by changing the server side. Instead of accessing a regular file, I convert the file to m3u8 in realtime, using ffmpeg. I then throw the m3u8 URI onto the player and it updates the duration of the stream (while playing) without the need to create any additional code on the client side.

Android MediaPlayer HLS change on KitKat 4.4.3

Can anyone shed light on the following problem? The android native mediaplayer seems to now use the PTS (Presentation Time Stamp) values in the transport stream to determine playback in the stream, rather than a simple counter. This behavior appeared to start with the 4.4.3 update. The symptoms of this are as follows:
The MediaController displays unhelpful values and no longer is able to be used to skip ahead or move back for streams that do not have PTS reset to zero in the first segment.
The MediaPlayer returns incorrect values for the getCurrentPosition() api call. Instead of starting at zero, it seems to use the PTS value, and ends returning multiple hours after only 1 second of playback, for example.
I am wondering if anyone can explain this behavior, or can reference a "feature" from this release of KitKat. The closest filed bug in Android I found is here. The player is used in a VideoView. The same playlists report expected numbers for getCurrentPosition() in earlier 4.4.2.
Thanks
It sounds like you're running into the same problem that a lot of people are having with HLS native video on 4.4.3 and 4.4.4: https://code.google.com/p/android/issues/detail?id=70877.
I haven't seen the presentation time stamp mentioned yet so it would be very helpful if you could share your findings on the bug ticket.

Rendering Closed Captions for HLS streams on Android

I'm working on a native Android application that streams HLS video. I'm trying to get CEA-608 closed caption data to display, but I'm running into a problem.
Methodology:
I'm running on a Jelly bean device (API 4.1+), which supports closed captions and HLS playback (http://developer.android.com/about/versions/android-4.1.html#Multimedia).
Test Feed:
I'm testing using the Apple sample HLS bip-bop feed that contains captions data (https://devimages.apple.com.edgekey.net/resources/http-streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8)
Grabbing Caption Data:
As per the Android documentation, I'm attempting to get the caption track by calling:
"MediaPlayer.getTrackInfo()"
Problem:
The player crashes when I execute the getTrackInfo() line, with the following output in LogCat:
E/AndroidRuntime(7311): FATAL EXCEPTION: main
E/AndroidRuntime(7311): java.lang.RuntimeException: failure code: -38
Questions:
1) Is closed caption rendering from in-stream caption data on an HLS feed supported in native Android apps?
2) If not, are there alternatives?
3) The documentation in the link above (quoted below) indicates that in-stream captions are supported on MP4 or 3GPP media sources. Does that necessarily exclude HLS (which I believe is MPEG-2 based) from working?
The MediaPlayer now handles both in-band and out-of-band text tracks.
In-band text tracks come as a text track within an MP4 or 3GPP media
source. Out-of-band text tracks can be added as an external text
source via addTimedTextSource() method. After all external text track
sources are added, getTrackInfo() should be called to get the
refreshed list of all available tracks in a data source.
Thanks for any help you can offer!
We went thru exactly same exercise. MediaPlayer on Android doesn't seem to support CEA-608 embedded in HLS. OnTimedTextListener was never called when media player (MP) was playing. On trying to call getTrackInfo() when MP was playing resulted in crash as you mentioned.
May be Android MP can decode only included SRT in MP4.
Alternative would be to use external timed text track but in live streaming environment, it is going to be difficult.
The question is quite old, but some people still might face the problem.
ExoPlayer tries to solve the issue as an Android version independent general multimedia library.
It currently supports CEA-608, SubRip, TTML, TX3g and WebVtt subtitles. Of course not fully all the standards, but a useful part of them.

Audio Crossfading in Android

I am develping a media player for my learning purpose and I want to have crossfading feature in media player app. But I don't have clue where to start from. i tried searching on inernet but no luck. I am using Android MediaPlayer class for all media player related operation. Anyone know any workaround to achieve the same.
thanks for your support
Try to use the AudioTrack instead of MediaPlayer. Generally, I'd suggest the following plan:
Learn some sources for an app that uses AudioTrack. A good player can be found here
This is an aac audio player that uses JNI for aac-audio decoding.
Find a MP3 decoding library. The library should be a Java one (look at this for example, or it is possible there are another libraries (I did not use such java libraries)) or a C/C++ library (in this case you also will use it through JNI).
When you will get simple working MP3 player, add manual crossfading (this should be easy, if you aware of basics of digital audio).
Try to use two objects of MediaPlayer one after another with crossfade, like in this class https://github.com/psaravan/JamsMusicPlayer/blob/f165057dd664727ed06b9fac2c27557e5fb7e7ee/jamsMusicPlayer/src/main/java/com/jams/music/player/Services/AudioPlaybackService.java
When second mediaPlayer stars first pauses for while (On some devices mostly on samsung )so transition is not smooth. MediaPlayer has this issue and its been reported to google since long ago but still not resolved(https://issuetracker.google.com/issues/36931073) so we can do nothing about it. So I used Exoplayer for playing audio and it works very smoothly without any pause.

fast forwarding Audio file using media player android

how to fast forwarding an Audio file using media player in android on seekbar progress change?
I would use the 'seekTo()'-method and jump about 10 or 20 seconds each time.
I don't think MediaPlayer can do much more than play/pause actually. I'm using SoundPool non-stop, so someone should correct me if I'm wrong here.
I think you might need to add different versions of the song (with different speed) and change the actual source each time you want to speed up.

Categories

Resources