Hello
I’m facing some issues while using Exoplayer in Xamarin forms android app.
1.) I’m not able to install the latest stable version of “Xam.Plugins.Android.ExoPlayer” plugin.
2.) I’ve installed “2.16.1” version of “Xam.Plugins.Android.ExoPlayer” plaugin and make the renderer but showing the blank screen so how we can overcome this issue please suggest me as soon as possible.
3.) I’ve created the video control in our xamarin forms project .
public class VideoPlayer : View
{
public static readonly BindableProperty SourceUrlProperty =
BindableProperty.Create(“SourceUrl”, typeof(string), typeof(VideoPlayer));
public string SourceUrl
{
get => (string)GetValue(SourceUrlProperty);
set => SetValue(SourceUrlProperty, value);
}
}
4.) And the renderer class like this
public class VideoPlayerRenderer : ViewRenderer<VideoPlayer, PlayerView>, IMediaSourceEventListener
{
private PlayerView _playerView;
private SimpleExoPlayer _player;
public VideoPlayerRenderer(Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<VideoPlayer> e)
{
base.OnElementChanged(e);
if (_player == null)
InitializePlayer();
Play();
}
private void InitializePlayer()
{
//_player = ExoPlayerFactory.NewSimpleInstance(Context, new DefaultTrackSelector());
// Passing Load Control
var loadControl = new DefaultLoadControl.Builder()
.SetBufferDurationsMs(25000, 50000, 1500, 2000).CreateDefaultLoadControl();
var dataSourceFactory = new DefaultDataSourceFactory(Context);
var renderersFactory = new DefaultRenderersFactory(Context).SetExtensionRendererMode(DefaultRenderersFactory.ExtensionRendererModePrefer);
// Create a progressive media source pointing to a stream uri.
var mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).CreateMediaSource(Android.Net.Uri.Parse("")); // new SimpleExoPlayer.Builder(Context, renderersFactory);
// Prepare the player with the media source.
// Create a player instance.
// Create a player instance.
_player = new SimpleExoPlayer.Builder(Context, renderersFactory).SetLoadControl(loadControl).Build();
_player.PlayWhenReady = true;
playerView = new PlayerView(Context) { Player = player };
SetNativeControl(_playerView);
}
private void Play()
{
try
{
Android.Net.Uri sourceUri = Android.Net.Uri.Parse(Element.SourceUrl);
//DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory("1");
//DefaultSsChunkSource.Factory ssChunkFactory = new DefaultSsChunkSource.Factory(httpDataSourceFactory);
//Handler emptyHandler = new Handler();
// Create a progressive media source pointing to a stream uri.
// Passing Load Control
var loadControl = new DefaultLoadControl.Builder()
.SetBufferDurationsMs(25000, 50000, 1500, 2000).CreateDefaultLoadControl();
var dataSourceFactory = new DefaultDataSourceFactory(Context, "com.airmemo.android");
var renderersFactory = new DefaultRenderersFactory(Context).SetExtensionRendererMode(DefaultRenderersFactory.ExtensionRendererModePrefer);
var ssMediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).CreateMediaSource(sourceUri); // new SimpleExoPlayer.Builder(Context, renderersFactory);
// Prepare the player with the media source.
//SsMediaSource ssMediaSource = new SsMediaSource(sourceUri, httpDataSourceFactory, ssChunkFactory, emptyHandler, this);
//_player.Prepare(ssMediaSource);
_player.SetMediaSource(ssMediaSource);
// Prepare the player with the media source.
_player.Prepare(ssMediaSource, true, true);
_player.Play();
}
catch (System.Exception ex)
{
var mesg = ex.Message;
}
}
public void OnDownstreamFormatChanged(int p0, Format p1, int p2, System.Object p3, long p4)
{
}
public void OnLoadCanceled(DataSpec p0, int p1, int p2, Format p3, int p4, System.Object p5, long p6, long p7, long p8, long p9, long p10)
{
}
public void OnLoadCompleted(DataSpec p0, int p1, int p2, Format p3, int p4, System.Object p5, long p6, long p7, long p8, long p9, long p10)
{
}
public void OnLoadError(DataSpec p0, int p1, int p2, Format p3, int p4, System.Object p5, long p6, long p7, long p8, long p9, long p10, IOException p11, bool p12)
{
}
public void OnLoadStarted(DataSpec p0, int p1, int p2, Format p3, int p4, System.Object p5, long p6, long p7, long p8)
{
}
public void OnUpstreamDiscarded(int p0, long p1, long p2)
{
}
}
5.) Also attached the screenshot here.
Thanks