Android ExoPlayer playing audio from URL cut out after white space - android

Streaming audio from URL stops after white space in audio, if we play the same URL on the browser it works fine.
ExoPlayer version: 2.13.2
Here is my ExoPlayer configuration:
player = new SimpleExoPlayer.Builder(context.get()).build();
player.setPlayWhenReady(true);
MediaItem mediaItem = new MediaItem.Builder()
.setUri("http://my audio url")
.setMimeType(MimeTypes.AUDIO_WAV)
.setClipEndPositionMs(TIME_END_OF_SOURCE)
.setClipRelativeToLiveWindow(false)
.setClipRelativeToDefaultPosition(true)
.build();
player.setMediaItem(mediaItem);
player.prepare();

Related

Exoplayer2 not playing MPD video

I am building a video player which streams online videos with track selector. If I parse mp4 video, Exoplayer plays the video well but when the video has mpd format, it plays but with black screen.
My code:
val trackSelector = DefaultTrackSelector(context)
val url = "https://storage.googleapis.com/wvmedia/cenc/h264/tears/tears.mpd"
val simpleExoPlayer = SimpleExoPlayer.Builder(context).setTrackSelector(trackSelector).build()
simpleExoPlayer.setMediaItem(MediaItem.fromUri(url))
simpleExoPlayer.seekTo(0)
simpleExoPlayer.prepare()
I have tried the code above and it works with all formats excepts mdp format.

How to play 5.1 audio in exoplayer android smart phone

I would like to play DD 5.1 Audio in my android app based on exoplayer. when i try to play video via my app it shows blank and audio is muted but same video and audio is playing via MX player or vlc player.
please let me know how to make my app support DD5.1 audio
image for supporting issue
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(Uri.parse(url)));
ExoTrackSelection.Factory videoTrackSelectionFactory = new
AdaptiveTrackSelection.Factory();
trackSelector = new
DefaultTrackSelector(Player.this, videoTrackSelectionFactory);
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);
renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
simpleExoPlayer = new SimpleExoPlayer.Builder(this, renderersFactory)
.setTrackSelector(trackSelector)
.setSeekForwardIncrementMs(10000)
.setSeekBackIncrementMs(10000)
.build();
playerView.setPlayer(simpleExoPlayer);
playerView.setKeepScreenOn(true);

Play HLS radio without player view in my Android app

I am developing an android app to play the HLS radio. I don't want to have a player view since there is no video track for the streaming. I want to control the audio playing by a play/pause button.
I did some google search and I found that there is a google official project called ExoPlayer which seems to have a feature of playing hls. I tried the example but it shows that it does not support the audio codec. Therefore, I wonder if there is any solution of
an example of Exoplayer for playing HLS audio in android app without any player view
any other solution to achieve my goal
Thank you!
Edited on 11th, May
The following part is my code, though it seems to be a deprecated method
DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
String userAgent = Util.getUserAgent(MainActivity.this, "ExoPlayerDemo");
DefaultDataSourceFactory mediaDataSourceFactory = new DefaultDataSourceFactory(MainActivity.this, BANDWIDTH_METER,
new DefaultHttpDataSourceFactory(userAgent, BANDWIDTH_METER));
HlsMediaSource mediaSource = new HlsMediaSource.Factory(mediaDataSourceFactory)
.createMediaSource(Uri.parse(url), null, null);
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
DefaultRenderersFactory renderersFactory =
new DefaultRenderersFactory(MainActivity.this, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
ExoPlayer player = ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector);
player.setPlayWhenReady(true);
if(mediaSource!=null) {
player.prepare(mediaSource);
}
I will try using the example code from official site with a player ui and I will use a layout to overlap on the ui. I will be grateful if there is any other suggestion.

Enable lazy buffering in ExoPlayer

I want to show video by http data source. but when I set data source, exoplayer immediately start to buffer video, How can start buffering on user play click.
val dataSourceFactory = DefaultDataSourceFactory(context,Util.getUserAgent(context!!,"user_agent"))
player = SimpleExoPlayer.Builder(context!!).build()
playerView!!.player = player
val contentUrl = "my video url.mp4"
videoSource = ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(contentUrl))
player.prepare(videoSource)
P.S:
I try to change DefaultLoadControl to change buffering behavior but I cant find a workaround.
Thanks.

Exoplayer, play an audio stream and a video stream synchronously?

I am using the following code to play a stream (which has both a video and an audio). But what if I want a video stream and a separate audio stream for the video stream at the same time synchronously? For example, suppose there are
https://someserver.com/video1/video.mp4
https://someserver.com/video1/audio.mp3
Both video.mp4 and audio.mp3 belong to video1 and have the same length, 1:23:34. Can I play video.mp4 and audio.mp3 synchronously as if they were one stream, with one ExoPlayer? The user must be able to pause/play/seek, and the same action should be applied to both streams.
If not, and I have to use two ExoPlayers, one for video and one for audio, how can I synchronise the audio and the video?
var uri = Uri.parse(url);
var df = DefaultHttpDataSourceFactory(url);
var ms = ExtractorMediaSource(uri, df, DefaultExtractorsFactory(), null, null);
exoPlayer.playWhenReady=true;
exoPlayer.prepare(ms);
You can! This is done in ExoPlayer by creating a MergingMediaSource. The example in the link merges a video source with a subtitle source but it's even easier for audio and video:
MediaSource videoSource = new ProgressiveMediaSource.Factory(...)
.createMediaSource(videoUri);
MediaSource audioSource = new ProgressiveMediaSource.Factory(...)
.createMediaSource(audioUri);
MergingMediaSource mergedSource = new MergingMediaSource(videoSource, audioSource);

Categories

Resources