Exoplayer cast extension with live streams - android

I'm trying the implement cast support to my androapp, when I use normal non live links such as MP4 and even HLS non live stream it works perfectly but, when I use live stream the stream just won't play at the chromecast.
This is how I create my MediaInfo:
MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
movieMetadata.putString(MediaMetadata.KEY_TITLE, "Test");
MediaInfo mediaInfo = new MediaInfo.Builder("HLS link")
.setStreamType(MediaInfo.STREAM_TYPE_LIVE).setContentType(MimeTypes.APPLICATION_M3U8)
.setMetadata(movieMetadata).build();
This is how I load the items:
castPlayer.loadItem(new MediaQueueItem.Builder(setCastMedia()).build(), 0);
This is the logcat I get:
W/MediaControlChannel: received unexpected error: Invalid Request. W/MediaQueue: Error fetching queue item ids, statusCode=2100, statusMessage=null
Any ideas what I'm doing wrong?
Happens the same with TS type streams...

With the following code, you can cast live streams using ExoPlayer.
MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_TV_SHOW);
movieMetadata.putString(MediaMetadata.KEY_TITLE, "Title");
MediaInfo mediaInfo = new MediaInfo.Builder("your_link.m3u8")
.setStreamType(MediaInfo.STREAM_TYPE_LIVE)
.setContentType(MimeTypes.APPLICATION_M3U8)
.setMetadata(movieMetadata)
.build();
MediaQueueItem mediaQueueItem = new MediaQueueItem.Builder(mediaInfo).build();
castPlayer.loadItem(mediaQueueItem, mediaQueueItem.getMedia().getStreamDuration());
castPlayer.setPlayWhenReady(true);

Related

Android WebRTC Local AudioTrack is not streaming audio

I am developing an android app with Audio call feature by using WebRTC. I have written the code with latest build available for android. When i receive a call from client, i am able to Connect client successfully. Problem is, i can hear client audio but my audio is not streaming to client. Below is the code.
factory = PeerConnectionFactory.builder()
.setAudioDeviceModule(adm)
.setOptions(options)
.createPeerConnectionFactory();
peerConnection = createPeerConnection(factory);
if(peerConnection != null){
remoteAudioSource = factory.createAudioSource(new MediaConstraints());
remoteAudioTrack = factory.createAudioTrack("5555",remoteAudioSource);
//Local audio track
List<String> mediaStreamLabels = Collections.singletonList("ARDAMS");
peerConnection.addTrack(createAudioTrack(),mediaStreamLabels);
peerConnection.setAudioRecording(true);
peerConnection.setAudioPlayout(true);
}
private AudioTrack createAudioTrack() {
localAudioSource = factory.createAudioSource(new MediaConstraints());
localAudioTrack = factory.createAudioTrack(AUDIO_TRACK_ID, localAudioSource);
localAudioTrack.setEnabled(true);//Enable audio
return localAudioTrack;
}

SimpleExoplayerView plays audio, screen is white

So I am trying to play a DASH video in a SimpleExoplayerView. I am following the most basic tutorials from https://codelabs.developers.google.com/codelabs/exoplayer-intro/#0.
The trouble is, I am able to hear the audio but the screen is always white.
Things I have already tried -
Using three different .mpd links. Can hear the audio each time and the video is white in each case. So there is no problem with the .mpd links.
Tested in different devices - an API 19 HTC Desire and an API 24 Moto G4. So I'm sure it is not a device specific issue.
Here is the initialising method -
private void initialisePlayer() {
TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory
(defaultBandwidthMeter);
if (exoPlayer == null) {
exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(context), new
DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl());
simpleExoPlayerView.setPlayer(exoPlayer);
exoPlayer.setPlayWhenReady(true);
DashMediaSource mediaSource = buildMediaResource();
exoPlayer.prepare(mediaSource);
}
}
And this is the buildMediaSource method -
private DashMediaSource buildMediaResource() {
String userAgent = Util.getUserAgent(context, getString(R.string.app_name));
DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent);
DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(new
DefaultHttpDataSourceFactory(userAgent, defaultBandwidthMeter));
return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory).createMediaSource(Uri
.parse(url));
}
Am I missing something?

Set min-buffer threshold for http/network playback

In a video player project, I'd like to use LibVLC http streaming from a slow source.
However, I can not get it to stream FIRST, and then continuously download data. The player will always stop in-between.
I'm using vlc-android from GIT.
This is the media player setup code:
ArrayList<String> options = new ArrayList<>();
options.add("--no-sub-autodetect-file");
options.add("--swscale-mode=0");
options.add("--network-caching=60000");
if (BuildConfig.DEBUG) {
options.add("-vvv"); // verbosity
}
libVLC = new LibVLC(options);
mediaPlayer = new org.videolan.libvlc.MediaPlayer(libVLC);
mediaPlayer.setEventListener(this);
final IVLCVout vout = mediaPlayer.getVLCVout();
vout.setVideoView(videoView);
vout.setSubtitlesView(subtitleView);
vout.addCallback(this);
vout.attachViews();
final Media media = new Media(libVLC, getIntent().getData());
media.setHWDecoderEnabled(true, false);
media.addOption(":network-caching=60000");
media.addOption(":clock-jitter=0");
media.addOption(":clock-synchro=0");
mediaPlayer.setMedia(media);
mediaPlayer.play();
I was hoping that setting the :network-caching on the media object is enough, but it seems to still run out of data the whole time.
How to configure LibVLC so that the stutter is eliminated? Some buffer time is OK.
The stream type is a MOV file served via HTTP.
libvlc option try it:
ArrayList<String> options = new ArrayList<String>();
options.add("--audio-time-stretch"); // time stretching
options.add("-vvv"); // verbosity
options.add("--no-audio"); // no audio
options.add("--aout=none");
options.add("--no-sub-autodetect-file");
options.add("--swscale-mode=0");
options.add("--network-caching=400");
options.add("--no-drop-late-frames");
options.add("--no-skip-frames");
options.add("--avcodec-skip-frame");
options.add("--avcodec-hw=any");
media addOption try it:
Media m = new Media(libvlc, Uri.parse(URL));
m.setHWDecoderEnabled(true, true);
m.addOption(":network-caching=5000");
m.addOption(":clock-jitter=0");
m.addOption(":clock-synchro=0");
m.addOption(":codec=all");
mMediaPlayer.setMedia(m);
mMediaPlayer.play();

Unable to some videos in chrome cast

I am using CastCompanionLibrary-android for chromecast integration.
I am going to show few methods of chromecast integration
first one is configuration initalization in application cast
private void initchromecast() {
String applicationId = getString(R.string.app_id);
// Build a CastConfiguration object and initialize VideoCastManager
CastConfiguration options = new CastConfiguration.Builder(applicationId)
.enableAutoReconnect()
.enableCaptionManagement()
.enableDebug()
.enableLockScreen()
.enableNotification()
.enableWifiReconnection()
.setCastControllerImmersive(true)
.setLaunchOptions(false, Locale.getDefault())
.setNextPrevVisibilityPolicy(CastConfiguration.NEXT_PREV_VISIBILITY_POLICY_DISABLED)
.addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_REWIND, false)
.addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true)
.addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true)
.setForwardStep(10)
.build();
VideoCastManager.initialize(this, options);
}
and TO pass meta data
private void loadRemoteMedia(int position, boolean autoPlay) {
MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
mediaMetadata.putString(MediaMetadata.KEY_TITLE, TITLE);
MediaInfo mediaInfo = new MediaInfo.Builder(
path)
.setContentType("application/x-mpegURL")
.setStreamType(MediaInfo.STREAM_TYPE_LIVE)
.setMetadata(mediaMetadata)
.setStreamDuration(MediaInfo.UNKNOWN_DURATION)
.build();
mCastManager.startVideoCastControllerActivity(getActivity(), mediaInfo, position, autoPlay);
}
Now my question is in below cod when i pass CastCompanion sample id 4F8B3483 ,i can successfully cast most of the videos but when i put my sample application reciver id some of the videos which works with their id does not work with mine.
For example http://iptvcanales.com/xw/peliculas.php?movie=006 url works with CastCompanion reciver id but not with mine id in my code.

Does Chromecast support Apple HLS?

In Chromecast's documentation it is stated that Chromecast does support HLS streams. But I cannot make it work.
I created a simple app that have one button that initiates playback. For MP4 files it works great, but not for HLS streams. This is how I start stream:
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String url = "http://planeta-online.tv:1935/vod/mp4:tvt.russia.time_laps_in_st_piter.flv/manifest.m3u8";
MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, "Subtitle");
movieMetadata.putString(MediaMetadata.KEY_TITLE, "Title");
movieMetadata.putString(MediaMetadata.KEY_STUDIO, "Studio");
movieMetadata.addImage(new WebImage(Uri.parse("http://cdn.planeta-online.tv/kp/app/icons/i5.png")));
movieMetadata.addImage(new WebImage(Uri.parse("http://cdn.planeta-online.tv/kp/app/icons/i5.png")));
MediaInfo mSelectedMedia = new MediaInfo.Builder(url)
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType("application/vnd.apple.mpegurl")
.setMetadata(movieMetadata)
.build();
mVideoCastManager.startCastControllerActivity(MainActivity.this, mSelectedMedia, 0, true);
}
});
I enabled CORS for this stream on Wowza, but it didn't help. Changing StreamType from MediaInfo.STREAM_TYPE_BUFFERED to MediaInfo.STREAM_TYPE_LIVE doesn't have any effect either. Any other ideas?
What receiver are you using? You can use either the Default receiver, or a Styled receiver; they both support HLS. Handling of adaptive streams is handled by the Media Player Library (MPL) and if you want to write your own custom receiver, you need to use that library; we have a sample that does that.
I've found that setting the contentType of the stream to "video/m3u" or "video/m3u8" (depending on your format) worked for my HLS streams with the Default receiver.

Categories

Resources