Baseflow / ExoPlayerXamarin

Xamarin bindings library for the Google ExoPlayer library
https://baseflow.com
MIT License
153 stars 66 forks source link

Sample documentation out of date. #135

Closed Zintom closed 1 year ago

Zintom commented 2 years ago

The sample documentation uses the SimpleExoPlayer class which has now been deprecated. The suggestion is to use the IExoPlayer interface.

I am trying to work out how to instantiate an IExoPlayer but am having no luck as the constructors I wish to use are only available on API 33 and above and the constructors which aren't are marked as obsolete.

Please could some guidance be provided on how to create an IExoPlayer in this latest release.

ScriptSun commented 2 years ago

Here is an Example

var Exoplayer = new IExoPlayer.Builder(MainContext).SetMediaSourceFactory(MainDataSource).Build();

MediaItem mediaItem = MediaItem.FromUri(Android.Net.Uri.Parse("https://wowonder.fra1.cdn.digitaloceanspaces.com/upload/videos/2022/11/PRjaipBn2Gmj4CEV1O4e_11_a509a30225863eb0c2e5cf08e343a826_video_720p_converted.mp4"));

HttpDataSourceFactory = new DefaultHttpDataSource.Factory().SetAllowCrossProtocolRedirects(true);

if (PlayerSettings.EnableOfflineMode) // Custom Function by us
{
    Cache = MainApplication.GetInstance().ExoCache;
    CacheFactoryDataSource = new CacheDataSource.Factory();
    CacheFactoryDataSource.SetCache(Cache).SetUpstreamDataSourceFactory(HttpDataSourceFactory).SetFlags(CacheDataSource.FlagIgnoreCacheOnError).SetEventListener(new CachEventListner());
}

MediaItem mediaItem = MediaItem.FromUri(Android.Net.Uri.Parse(trackurl));
Exoplayer.AddMediaItem(mediaItem);
Exoplayer.Prepare();
Exoplayer.Play();
Zintom commented 2 years ago

@ScriptSun Thanks for the example.

How are you defining MainDataSource?

Using a DefaultMediaSourceFactory with a DefaultHttpDataSource fails with the following error: "Failed resolution of: Lcom/google/common/base/Supplier;"

ArchangelWTF commented 2 years ago

@Zintom Include Guava in your project or revert to 2.18.3, it seems a new version was pushed from my fork in which I was tinkering as to why Guava wasn't working in someone else's issue.

Zintom commented 2 years ago

@ArchangelWTF Cheers for that. Will this be fixed in a future official release?

ArchangelWTF commented 2 years ago

Yeah I've already made a PR just now that reverts the change just need it to be merged in.