I am working on music app where i play music from url. I am new to ExoPlayer, i don't know how to get metadata information from ExoPlayer. I want to show metadata info in notification.
I have used MediaSource for passing source to ExoPlayer like this :
MediaSource mediaSources = new ExtractorMediaSource(Uri.parse("***.mp3"),
dataSourceFactory, extractorsFactory, null, null);
Any possibility to get metadata from ExoPlayer?
With version 2.1 you can listen metadata. Just add
public void addMetadataOutput(MetadataOutput listener)
to SimpleExoPlayer.
Related
I am creating MP3 player using exoplayer.
I have online tracks with DRM(Widevine) protection so exoplayer call HttpMediaDrmCallback for get license key to play DRM protected content.
After set track to the exoplayer it's takes 5 second to calls executeKeyRequest from HttpMediaDrmCallback class, how can I decreased the time
Set tracks to the exoplayer
DefaultTrackSelector trackSelector = new DefaultTrackSelector(this);
ExoPlayer exoplayer = new ExoPlayer.Builder(this)
.setTrackSelector(trackSelector)
.build();
exoplayer.setMediaSources(mediaSources); // I already created this object before
exoplayer.prepare();
exoplayer.seekTo(0, C.TIME_UNSET);
exoplayer.setPlayWhenReady(true);
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.
How to play multiple URLs sequentially in android? I have a small streaming url 10s/each of one complete song. I need to play it one after another. Is there any way doing it so the music don't get lagged?
https://exoplayer.dev/media-sources.html read Advanced composition
MediaSource firstSource =
new ProgressiveMediaSource.Factory(...).createMediaSource(firstVideoUri);
MediaSource secondSource =
new ProgressiveMediaSource.Factory(...).createMediaSource(secondVideoUri);
// Plays the first video twice, then the second video.
ConcatenatingMediaSource concatenatedSource =
new ConcatenatingMediaSource(firstSource, firstSource, secondSource);
It looks like you are using the m3u8 playlist to play with MediaPlayer. However, you wouldn't able to do it. You can use ExoPlayer to play m3u8 list. Check this link
https://github.com/google/ExoPlayer
simpleExoPlayerView.setShowMultiWindowTimeBar(true);
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);
I have more than one video to play one by one. After Creating MediaSource of each video, All these are going to ConcatenatingMediaSource(mediaSources[]). Normally it play one by one. But when video is fast forward using seekTo(), 1st video is ok but other videos do not follow seekTo().
Suppose 1st video is 10s, 2nd 12s, 3rd 10s.
If I call seekTo((long)12*1000) it should play 2nd video with 2s forward. But it plays from the beginning of 2nd video.
Setting VideoSources
DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),Util.getUserAgent(getApplicationContext(), "ExoPlayer"));
MediaSource mediaSource = new ExtractorMediaSource.Factory(defaultDataSourceFactory).createMediaSource(videoItem.getVideoUri());
videoItemArrayList.get(k).setVideoSource(mediaSource);
Concatenate Sources
MediaSource[] mediaSources = new MediaSource[videoItemArrayList.size()];
int j=0;
for(VideoItem item : videoItemArrayList){
mediaSources[j] = item.getVideoSource();
++j;
}
concatenatedSource = new ConcatenatingMediaSource(mediaSources);
Setup exoplayer
exoPlayer.prepare(concatenatedSource);
exoPlayer.seekTo(0);
exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlaybackState();
Using exoplayer.seekTo(period) internally calls currentWindowIndex() internally of the source. While you are playing the first video in the concatenated mediasource you end up receiving windowIndex as 0. Use seekTo(windowIndex, time) to solve the issue.