private IMediaSource GetMediaSourceFromUrl(Uri uri, string tag) { try { var mBandwidthMeter = new DefaultBandwidthMeter(); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(ActivityContext, Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), mBandwidthMeter); var buildHttpDataSourceFactory = new DefaultDataSourceFactory(ActivityContext, mBandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), new DefaultBandwidthMeter())); var buildHttpDataSourceFactoryNull = new DefaultDataSourceFactory(ActivityContext, mBandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), null)); int type = Util.InferContentType(uri, null); var src = type switch { C.TypeSs => new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).CreateMediaSource(uri), C.TypeDash => new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).CreateMediaSource(uri), C.TypeHls => new HlsMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri), C.TypeOther => new ExtractorMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri), _ => new ExtractorMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri) }; return(src); } catch (Exception e) { Console.WriteLine(e); return(null); } }
public void playVideo(string url, string typestream) { var MyURL = url; var mediaUri = Android.Net.Uri.Parse(MyURL); var userAgent = Util.GetUserAgent(this, "Player"); var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent); var defaultDataSourceFactory = new DefaultDataSourceFactory(this, null, defaultHttpDataSourceFactory); if (typestream == "HLS") { playerView.UseController = false; extractorMediaSource = new HlsMediaSource.Factory(defaultDataSourceFactory).CreateMediaSource(mediaUri); } else if (typestream == "MP4") { extractorMediaSource = new ExtractorMediaSource(mediaUri, defaultDataSourceFactory, new DefaultExtractorsFactory(), null, null); } ConcatenatingMediaSource concatenatedSource = new ConcatenatingMediaSource(extractorMediaSource); var defaultBandwidthMeter = new DefaultBandwidthMeter(); var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter); var defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); player = ExoPlayerFactory.NewSimpleInstance(this, defaultTrackSelector); player.Prepare(concatenatedSource); player.AddListener(new CustomListener()); playerView.Player = player; player.PlayWhenReady = true; }
public void Play(string url) { if (clicks % 2 == 0) { #region ExoPlayer var mediaUrl = url; var mediaUri = Android.Net.Uri.Parse(mediaUrl); Android.Content.Context context = Android.App.Application.Context; var userAgent = Util.GetUserAgent(context, "InstationPlayer"); var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent); var defaultDataSourceFactory = new DefaultDataSourceFactory(context, null, defaultHttpDataSourceFactory); var extractorMediaSource = new ExtractorMediaSource(mediaUri, defaultDataSourceFactory, new DefaultExtractorsFactory(), null, null); var defaultBandwidthMeter = new DefaultBandwidthMeter(); var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter); var defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); exoPlayer = ExoPlayerFactory.NewSimpleInstance(context, defaultTrackSelector); exoPlayer.Prepare(extractorMediaSource); Console.WriteLine("Prepared"); exoPlayer.PlayWhenReady = true; Console.WriteLine("Started"); clicks++; #endregion } else if (clicks % 2 != 0) { exoPlayer.Stop(); Console.WriteLine("Paused"); clicks++; } }
private IMediaSource GetMediaSourceFromUrl(Uri uri, string extension, string tag, IDrmSessionManager drmSessionManager) { try { var BandwidthMeter = DefaultBandwidthMeter.GetSingletonInstance(ActivityContext); //DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(MainContext, Util.GetUserAgent(MainContext, AppSettings.ApplicationName), mBandwidthMeter); var buildHttpDataSourceFactory = new DefaultDataSourceFactory(ActivityContext, BandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName))); var buildHttpDataSourceFactoryNull = new DefaultDataSourceFactory(ActivityContext, BandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName))); int type = Util.InferContentType(uri, extension); IMediaSource src = type switch { C.TypeSs => new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).SetDrmSessionManager(drmSessionManager).SetDrmSessionManager(IDrmSessionManager.DummyDrmSessionManager).CreateMediaSource(uri), C.TypeDash => new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).SetDrmSessionManager(drmSessionManager).SetDrmSessionManager(IDrmSessionManager.DummyDrmSessionManager).CreateMediaSource(uri), C.TypeHls => new HlsMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).SetDrmSessionManager(IDrmSessionManager.DummyDrmSessionManager).SetDrmSessionManager(drmSessionManager).CreateMediaSource(uri), C.TypeOther => new ProgressiveMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).SetDrmSessionManager(drmSessionManager).CreateMediaSource(uri), _ => new ProgressiveMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).SetDrmSessionManager(drmSessionManager).CreateMediaSource(uri) }; return(src); } catch (Exception e) { Methods.DisplayReportResultTrack(e); return(null !); } }
protected override void OnElementChanged(ElementChangedEventArgs <ExtendedVideoPlayer> e) { base.OnElementChanged(e); string s = Element.Source; // // Will be invoked by the Xamarin.Forms page when the last is closed // Element.ReleaseAction = PlayerRelease; _exoSpot = new PlayerView(Context); // // Video will be expanded on full screen // _exoSpot.SetResizeMode(AspectRatioFrameLayout.ResizeModeFit); SetNativeControl(_exoSpot); // // Create a default TrackSelector // Handler mainHandler = new Handler(); IBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // // Create the player // _exoPlayer = ExoPlayerFactory.NewSimpleInstance(Context, trackSelector); _exoPlayer.AddListener(new ExtendedVideoPlayerEventListener(_exoPlayer)); _exoPlayer.PlayWhenReady = true; // // Attach player to the view // _exoSpot.Player = _exoPlayer; DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(Context, Util.GetUserAgent(Context, Context.GetString(Resource.String.application_name))); IMediaSource videoSource = new ExtractorMediaSource( Android.Net.Uri.Parse(Element.Source), new CacheableDataSource(Context, 100 * 1024 * 1024, 5 * 1024 * 1024), new DefaultExtractorsFactory(), null, null); // // Prepare the player with the source. // _exoPlayer.Prepare(videoSource); }
public void StartPlaying(string url) { State = State.Loading; Uri uri = Uri.Parse(url); IDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(Application.Context, Application.Context.PackageName); IMediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).CreateMediaSource(uri); _exoPlayer.Prepare(mediaSource); }
public async Task StartPlaying(string url) { var context = Android.App.Application.Context.ApplicationContext; var player = new SimpleExoPlayer.Builder(context).Build(); var datasourceFactory = new DefaultDataSourceFactory(context, Util.GetUserAgent(context, "test")); var mediaSource = new ProgressiveMediaSource.Factory(datasourceFactory).CreateMediaSource(Uri.Parse("https://ia800605.us.archive.org/32/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3")); player.Prepare(mediaSource); player.PlayWhenReady = true; }
private static CacheDataSourceFactory BuildReadOnlyCacheDataSource( DefaultDataSourceFactory upstreamFactory, ICache cache) { return(new CacheDataSourceFactory( cache, upstreamFactory, new FileDataSourceFactory(), /* cacheWriteDataSinkFactory= */ null, CacheDataSource.FlagIgnoreCacheOnError, /* eventListener= */ null)); }
public XCacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) { this.context = context; this.maxCacheSize = maxCacheSize; this.maxFileSize = maxFileSize; var userAgent = Util.GetUserAgent(context, "ExoPlayerShit"); var bandwidthMeter = new DefaultBandwidthMeter(); defaultDatasourceFactory = new DefaultDataSourceFactory(context, bandwidthMeter, new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter)); }
public void SetMediaUrlSource(string url) { // Produces DataSource instances through which media data is loaded. var dataSourceFactory = new DefaultDataSourceFactory(_context, Util.GetUserAgent(_context, "ExoPlayerTest"), _defaultBandwidthMeter); // Produces Extractor instances for parsing the media data. var extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. var uri = Android.Net.Uri.Parse(url); _videoSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null); }
public RadioPlayer(Context context, string url) { _sourceUrl = url; #pragma warning disable 612, 618 var agent = WebSettings.GetDefaultUserAgent(context); var factory = new DefaultDataSourceFactory(context, agent); var extractorMediaSource = new ExtractorMediaSource(Android.Net.Uri.Parse(url), factory, new DefaultExtractorsFactory(), null, null); _exoPlayer = ExoPlayerFactory.NewSimpleInstance(context); _exoPlayer.Prepare(extractorMediaSource); #pragma warning restore 612, 618 }
private IMediaSource GetMediaSourceFromUrl(Uri uri, string extension, string tag) { var BandwidthMeter = DefaultBandwidthMeter.GetSingletonInstance(ActivityContext); //DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(ActivityContext, Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), mBandwidthMeter); var buildHttpDataSourceFactory = new DefaultDataSourceFactory(ActivityContext, BandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName))); var buildHttpDataSourceFactoryNull = new DefaultDataSourceFactory(ActivityContext, BandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName))); int type = Util.InferContentType(uri, extension); try { IMediaSource src; switch (type) { case C.TypeSs: src = new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).SetDrmSessionManager(IDrmSessionManager.DummyDrmSessionManager).CreateMediaSource(uri); break; case C.TypeDash: src = new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).SetDrmSessionManager(IDrmSessionManager.DummyDrmSessionManager).CreateMediaSource(uri); break; case C.TypeHls: DefaultHlsExtractorFactory defaultHlsExtractorFactory = new DefaultHlsExtractorFactory(DefaultTsPayloadReaderFactory.FlagAllowNonIdrKeyframes, true); src = new HlsMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).SetExtractorFactory(defaultHlsExtractorFactory).CreateMediaSource(uri); break; case C.TypeOther: default: src = new ProgressiveMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri); break; } return(src); } catch (Exception e) { Methods.DisplayReportResultTrack(e); try { return(new ProgressiveMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri)); } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); return(null !); } } }
public CacheableDataSource(Context context, long maxCacheSize, long maxFileSize) { _context = context; _maxCacheSize = maxCacheSize; _maxFileSize = maxFileSize; string userAgent = Util.GetUserAgent(context, _context.GetString(Resource.String.application_name)); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); _defaultDatasourceFactory = new DefaultDataSourceFactory( this._context, bandwidthMeter, new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter)); }
/// <summary> /// Plays the video contained in the URL at the given starting position. /// </summary> /// <param name="url">The URL.</param> /// <param name="position">The position.</param> private void PlayVideo(string url, long?position) { LoadingSpinnerView.Visibility = ViewStates.Visible; LoadingSpinnerView.Start(); // // Prepare the standard HTTP information for the source. // var mediaUri = global::Android.Net.Uri.Parse(url); var userAgent = Util.GetUserAgent(Activity, "Crex"); var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent); var defaultDataSourceFactory = new DefaultDataSourceFactory(Activity, null, defaultHttpDataSourceFactory); IMediaSource source; // // Determine if this is an HLS or MP4 stream. // if (mediaUri.Path.EndsWith(".m3u8", StringComparison.InvariantCultureIgnoreCase) || mediaUri.Path.EndsWith("/hsl", StringComparison.InvariantCultureIgnoreCase)) { using (var factory = new HlsMediaSource.Factory(defaultDataSourceFactory)) { source = factory.CreateMediaSource(mediaUri); } } else { using (var factory = new ExtractorMediaSource.Factory(defaultDataSourceFactory)) { source = factory.CreateMediaSource(mediaUri); } } // // Create the player and get it ready for playback. // AutoPlay = true; VideoPlayer = ExoPlayerFactory.NewSimpleInstance(Activity, new DefaultTrackSelector()); VideoPlayer.AddListener(this); PlayerView.Player = VideoPlayer; if (position.HasValue) { VideoPlayer.SeekTo(position.Value); } VideoPlayer.Prepare(source, !position.HasValue, false); }
private void SetPlayer() { try { AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(); var trackSelector = new DefaultTrackSelector(trackSelectionFactory); trackSelector.SetParameters(new DefaultTrackSelector.ParametersBuilder().Build()); VideoPlayer = ExoPlayerFactory.NewSimpleInstance(MainContext, trackSelector); DefaultDataSourceFac = new DefaultDataSourceFactory(MainContext, Util.GetUserAgent(MainContext, AppSettings.ApplicationName), BandwidthMeter); VideoSurfaceView.UseController = true; VideoSurfaceView.Player = VideoPlayer; } catch (Exception e) { Console.WriteLine(e); } }
private void SetPlayer() { try { var BandwidthMeter = DefaultBandwidthMeter.GetSingletonInstance(this); DefaultTrackSelector trackSelector = new DefaultTrackSelector(this); trackSelector.SetParameters(new DefaultTrackSelector.ParametersBuilder(this)); VideoPlayer = new SimpleExoPlayer.Builder(this).SetTrackSelector(trackSelector).Build(); DefaultDataSourceFac = new DefaultDataSourceFactory(this, Util.GetUserAgent(this, AppSettings.ApplicationName), BandwidthMeter); VideoSurfaceView.UseController = true; VideoSurfaceView.Player = VideoPlayer; } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private IMediaSource GetMediaSourceFromUrl(Uri uri, string tag) { try { var mBandwidthMeter = new DefaultBandwidthMeter(); //DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(ActivityContext, Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), mBandwidthMeter); var buildHttpDataSourceFactory = new DefaultDataSourceFactory(ActivityContext, mBandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), new DefaultBandwidthMeter())); var buildHttpDataSourceFactoryNull = new DefaultDataSourceFactory(ActivityContext, mBandwidthMeter, new DefaultHttpDataSourceFactory(Util.GetUserAgent(ActivityContext, AppSettings.ApplicationName), null)); int type = Util.InferContentType(uri, null); IMediaSource src; switch (type) { case C.TypeSs: src = new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).CreateMediaSource(uri); break; case C.TypeDash: src = new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(buildHttpDataSourceFactory), buildHttpDataSourceFactoryNull).SetTag(tag).CreateMediaSource(uri); break; case C.TypeHls: src = new HlsMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri); break; case C.TypeOther: src = new ExtractorMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri); break; default: //src = Exception("Unsupported type: " + type); src = new ExtractorMediaSource.Factory(buildHttpDataSourceFactory).SetTag(tag).CreateMediaSource(uri); break; } return(src); } catch (Exception e) { Console.WriteLine(e); return(null); } }
private void Play() { var userAgent = Util.GetUserAgent(Context, "App1"); defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent); defaultDataSourceFactory = new DefaultDataSourceFactory(Context, null, defaultHttpDataSourceFactory); if (Element.Source is UriVideoSource) { string uri = (Element.Source as UriVideoSource).Uri; if (!System.String.IsNullOrWhiteSpace(uri)) { _player.Prepare(BuildMediaSource(Android.Net.Uri.Parse(uri), "")); } } else if (Element.Source is FileVideoSource) { string filename = (Element.Source as FileVideoSource).File; if (!System.String.IsNullOrWhiteSpace(filename)) { //TODO: Implement File Input [NOT SURE IF NEEDED THOUGH] } } else if (Element.Source is ResourceVideoSource) { string package = Context.PackageName; string path = (Element.Source as ResourceVideoSource).Path; if (!System.String.IsNullOrWhiteSpace(path)) { string filename = Path.GetFileNameWithoutExtension(path).ToLowerInvariant(); string uri = "android.resource://" + package + "/raw/" + filename; _player.Prepare(new ExtractorMediaSource.Factory(defaultDataSourceFactory).CreateMediaSource(Android.Net.Uri.Parse(uri))); } } _player.AddListener(this); }
public void PlayAudio(string url) { if (isPlaying) { Stop(); } current_url = url; var context = Android.App.Application.Context; var mediaUri = Android.Net.Uri.Parse(url); var userAgent = Util.GetUserAgent(context, "GlobalFM"); var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent); var defaultDataSourceFactory = new DefaultDataSourceFactory(context, null, defaultHttpDataSourceFactory); var extractorMediaSource = new ExtractorMediaSource(mediaUri, defaultDataSourceFactory, new DefaultExtractorsFactory(), null, null); var defaultBandwidthMeter = new DefaultBandwidthMeter(); var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter); var defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); player = ExoPlayerFactory.NewSimpleInstance(context, defaultTrackSelector); player.Prepare(extractorMediaSource); player.PlayWhenReady = true; isPlaying = true; }
public IMediaSource CreateMediaSource(Uri uri) { int type = Util.InferContentType(uri); var dataSourceFactory = new DefaultDataSourceFactory(Activity.ActivityContext, Util.GetUserAgent(Activity.ActivityContext, AppSettings.ApplicationName)); switch (type) { case C.TypeDash: return(new DashMediaSource.Factory(dataSourceFactory).SetTag("Ads").CreateMediaSource(uri)); case C.TypeSs: return(new SsMediaSource.Factory(dataSourceFactory).SetTag("Ads").CreateMediaSource(uri)); case C.TypeHls: return(new HlsMediaSource.Factory(dataSourceFactory).SetTag("Ads").CreateMediaSource(uri)); case C.TypeOther: return(new ExtractorMediaSource.Factory(dataSourceFactory).SetTag("Ads").CreateMediaSource(uri)); default: return(new ExtractorMediaSource.Factory(dataSourceFactory).SetTag("Ads").CreateMediaSource(uri)); } }
public void Start() { if (_player != null) { Stop(); } _handler.Post(() => { try { var defaultBandwidthMeter = new DefaultBandwidthMeter(); var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter); var defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); _player = ExoPlayerFactory.NewSimpleInstance(_context, defaultTrackSelector); _player.AddListener(this); _player.PlayWhenReady = true; if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var audioFocusRequest = new AudioFocusRequestClass.Builder(AudioFocus.Gain) .SetOnAudioFocusChangeListener(this) .SetAudioAttributes(new AudioAttributes.Builder() .SetUsage(AudioUsageKind.Media) .SetContentType(AudioContentType.Music) .Build()) .Build(); if (_audioManager.RequestAudioFocus(audioFocusRequest) == AudioFocusRequest.Granted) { play(); } } else { #pragma warning disable CS0618 // Type or member is obsolete if (_audioManager.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain) == AudioFocusRequest.Granted) { play(); } #pragma warning restore CS0618 // Type or member is obsolete } } catch (Exception ex) { //Log.Error(TAG, $"Could not start player: {ex.Message}"); //Log.Debug(TAG, ex.ToString()); Error?.Invoke(this, new RadioStationErrorEventArgs(ex)); IsPlaying = false; } }); void play() { var mediaUri = Android.Net.Uri.Parse(StreamUrl); var userAgent = Util.GetUserAgent(_context, "wzxv.app.radio.player"); var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent); var defaultDataSourceFactory = new DefaultDataSourceFactory(_context, null, defaultHttpDataSourceFactory); var mediaSourceFactory = new ExtractorMediaSource.Factory(defaultDataSourceFactory); var mediaSource = mediaSourceFactory.CreateMediaSource(mediaUri); _player.Prepare(mediaSource); IsPlaying = true; } }
/** Returns a {@link DataSource.Factory}. */ public IDataSourceFactory BuildDataSourceFactory(ITransferListener listener) { DefaultDataSourceFactory upstreamFactory = new DefaultDataSourceFactory(this, listener, BuildHttpDataSourceFactory(listener)); return(BuildReadOnlyCacheDataSource(upstreamFactory, GetDownloadCache())); }
public virtual void Initialize() { if (Player != null) { return; } if (MediaSession == null) { throw new ArgumentNullException(nameof(MediaSession)); } if (RequestHeaders?.Count > 0 && RequestHeaders.TryGetValue("User-Agent", out string userAgent)) { UserAgent = userAgent; } else { UserAgent = Util.GetUserAgent(Context, "MediaManager"); } HttpDataSourceFactory = new DefaultHttpDataSourceFactory(UserAgent); if (RequestHeaders?.Count > 0) { foreach (var item in RequestHeaders) { HttpDataSourceFactory.DefaultRequestProperties.Set(item.Key, item.Value); } } DataSourceFactory = new DefaultDataSourceFactory(Context, null, HttpDataSourceFactory); DashChunkSourceFactory = new DefaultDashChunkSource.Factory(DataSourceFactory); SsChunkSourceFactory = new DefaultSsChunkSource.Factory(DataSourceFactory); BandwidthMeter = new DefaultBandwidthMeter(); TrackSelectionFactory = new AdaptiveTrackSelection.Factory(BandwidthMeter); TrackSelector = new DefaultTrackSelector(TrackSelectionFactory); MediaSource = new ConcatenatingMediaSource(); Player = ExoPlayerFactory.NewSimpleInstance(Context, TrackSelector); var audioAttributes = new Com.Google.Android.Exoplayer2.Audio.AudioAttributes.Builder() .SetUsage(C.UsageMedia) .SetContentType(C.ContentTypeMusic) .Build(); Player.AudioAttributes = audioAttributes; //TODO: Use this in 2.9.0 //Player.SetAudioAttributes(audioAttributes, true); PlayerEventListener = new PlayerEventListener() { OnPlayerErrorImpl = (exception) => { MediaManager.OnMediaItemFailed(this, new MediaItemFailedEventArgs(MediaManager.MediaQueue.Current, exception, exception.Message)); }, OnTracksChangedImpl = (trackGroups, trackSelections) => { MediaManager.MediaQueue.CurrentIndex = Player.CurrentWindowIndex; //TODO: Update metadata of item here } }; Player.AddListener(PlayerEventListener); PlaybackController = new PlaybackController(); MediaSessionConnector = new MediaSessionConnector(MediaSession, PlaybackController); QueueNavigator = new QueueNavigator(MediaSession); MediaSessionConnector.SetQueueNavigator(QueueNavigator); QueueDataAdapter = new QueueDataAdapter(MediaSource); MediaSourceFactory = new QueueEditorMediaSourceFactory(); TimelineQueueEditor = new TimelineQueueEditor(MediaSession.Controller, MediaSource, QueueDataAdapter, MediaSourceFactory); MediaSessionConnector.SetQueueEditor(TimelineQueueEditor); RatingCallback = new RatingCallback(); MediaSessionConnector.SetRatingCallback(RatingCallback); PlaybackPreparer = new MediaSessionConnectorPlaybackPreparer(Player, MediaSource); MediaSessionConnector.SetPlayer(Player, PlaybackPreparer, null); }
public void Startup() { /*** NEW PLAYER ***/ _player = ExoPlayerFactory.NewSimpleInstance(Context, new DefaultTrackSelector()); _player.PlayWhenReady = true; _player.AddListener(this); progress?.Dispose(); clipper?.Dispose(); progress = new ProgressTracker(_player); progress.OnPositionChange += Progress_OnPositionChange; clipper = new ProgressTracker(_player, 50); clipper.OnPositionChange += Clipper_OnPositionChange; _playerView = FindViewById <PlayerView>(Resource.Id.videoview); Android.Graphics.Typeface subtitleTypeface = ResourcesCompat.GetFont(Context, Resource.Font.montserratregular); var captionStyleCompat = new CaptionStyleCompat(Android.Graphics.Color.White, Android.Graphics.Color.Transparent, Android.Graphics.Color.Transparent, CaptionStyleCompat.EdgeTypeNone, Android.Graphics.Color.Transparent, subtitleTypeface); _playerView.SubtitleView.SetStyle(captionStyleCompat); _playerView.SubtitleView.SetFractionalTextSize(0.06f); //_playerView.SubtitleView.SetFixedTextSize((int)ComplexUnitType.Sp, 10); _playerView.SubtitleView.SetBottomPaddingFraction(0.4f); _playerView.SubtitleView.TextAlignment = TextAlignment.Center; _playerView.Player = _player; _playerView.UseController = true; webclient = new OkHttpClient.Builder() .Cache((Context.ApplicationContext as BootleggerApp).FilesCache) .Build(); httpDataSourceFactory = new OkHttpDataSourceFactory(webclient, "BootleggerEditor", null); extractorsFactory = new DefaultExtractorsFactory(); defaultDataSourceFactory = new DefaultDataSourceFactory(Context, "BootleggerEditor"); /*************/ _audioPlayer = ExoPlayerFactory.NewSimpleInstance(Context, new DefaultTrackSelector()); _audioPlayer.Volume = 0.4f; _audioPlayer.RepeatMode = Player.RepeatModeOne; cursor = FindViewById <View>(Resource.Id.trackposition); seeker = FindViewById <RangeSliderControl>(Resource.Id.seeker); trackcontrols = FindViewById <View>(Resource.Id.trackcontrols); seeker.LowerValueChanged += Seeker_LeftValueChanged; seeker.UpperValueChanged += Seeker_RightValueChanged; seeker.StepValueContinuously = true; track = FindViewById <View>(Resource.Id.track); title = FindViewById <TextView>(Resource.Id.title); FindViewById <ImageButton>(Resource.Id.fullscreenbtn).Click += Fullscreen_Click; videoWrapper = FindViewById(Resource.Id.videoWrapper); mFullScreenDialog = new FullScreenVideoDialog(Context, Android.Resource.Style.ThemeBlackNoTitleBarFullScreen); mFullScreenDialog.OnAboutToClose += MFullScreenDialog_OnAboutToClose; seeker.Visibility = ViewStates.Invisible; }
void SetSource() { isPrepared = false; bool hasSetSource = false; DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory("1"); DefaultSsChunkSource.Factory ssChunkFactory = new DefaultSsChunkSource.Factory(httpDataSourceFactory); Handler emptyHandler = new Handler(); IMediaSource videoSource = null; if (Element.Source is HLSVideoSource) { string uri = (Element.Source as HLSVideoSource).Uri; if (!string.IsNullOrWhiteSpace(uri)) { //videoView.SetVideoURI(Android.Net.Uri.Parse(uri)); videoSource = new HlsMediaSource(Android.Net.Uri.Parse(uri), httpDataSourceFactory, emptyHandler, null); hasSetSource = true; } } else if (Element.Source is UriVideoSource) { string uri = (Element.Source as UriVideoSource).Uri; if (!string.IsNullOrWhiteSpace(uri)) { //videoView.SetVideoURI(Android.Net.Uri.Parse(uri)); var dataSourceFactory = new DefaultDataSourceFactory(Context, Util.GetUserAgent(Context, "Multimedia")); videoSource = new ExtractorMediaSource(Android.Net.Uri.Parse(uri), dataSourceFactory, new DefaultExtractorsFactory(), emptyHandler, null); hasSetSource = true; } } else if (Element.Source is FileVideoSource) { string filename = (Element.Source as FileVideoSource).File; if (!string.IsNullOrWhiteSpace(filename)) { DataSpec dataSpec = new DataSpec(Android.Net.Uri.FromFile(new Java.IO.File(filename))); FileDataSource fileDataSource = new FileDataSource(); try { fileDataSource.Open(dataSpec); } catch (FileDataSource.FileDataSourceException e) { e.PrintStackTrace(); } // videoView.SetVideoPath(filename); IDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this.Context, "CloudMusic"); videoSource = new ExtractorMediaSource(fileDataSource.Uri, dataSourceFactory, new DefaultExtractorsFactory(), emptyHandler, null); hasSetSource = true; } } else if (Element.Source is ResourceVideoSource) { string package = Context.PackageName; string path = (Element.Source as ResourceVideoSource).Path; if (!string.IsNullOrWhiteSpace(path)) { string filename = Path.GetFileNameWithoutExtension(path).ToLowerInvariant(); string uri = "android.resource://" + package + "/raw/" + filename; //videoView.SetVideoURI(Android.Net.Uri.Parse(uri)); videoSource = new SsMediaSource(Android.Net.Uri.Parse(uri), httpDataSourceFactory, ssChunkFactory, emptyHandler, null); hasSetSource = true; } } if (videoSource != null) { ExoPlayer.Prepare(videoSource); } if (hasSetSource && Element.AutoPlay) { ExoPlayer.PlayWhenReady = true; // videoView.Start(); } }
//private void Preview_Click(object sender, EventArgs e) //{ // Intent sharingIntent = new Intent(Intent.ActionSend); // sharingIntent.SetType("text/plain"); // sharingIntent.PutExtra(Intent.ExtraSubject, shareedit.title); // sharingIntent.PutExtra(Intent.ExtraText, Bootlegger.BootleggerClient.server + "/v/" + shareedit.shortlink); // StartActivity(Intent.CreateChooser(sharingIntent, new Java.Lang.String(Resources.GetString(Resource.String.sharevia)))); //} public async void PlayVideo(MediaItem media) { Bootlegger.BootleggerClient.LogUserAction("Preview", new KeyValuePair <string, string>("mediaid", media.id)); if (Intent.GetBooleanExtra(Review.INGEST_MODE, false)) { var rv = FindViewById <RecyclerView>(Resource.Id.list); rv.SetLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false)); var _readonly = Intent.GetBooleanExtra(Review.READ_ONLY, false); var chips = new ChipAdapter(this, _readonly); //var prev = Resources.GetStringArray(Resource.Array.default_edit_topics).ToList(); //if (string.IsNullOrEmpty(Bootlegger.BootleggerClient.CurrentEvent.topics)) // Bootlegger.BootleggerClient.CurrentEvent.topics = string.Join(",", prev); //else //prev = Bootlegger.BootleggerClient.CurrentEvent.topics.Split(',').ToList(); if (_readonly) { chips.Update(null, media); } else { chips.Update(Bootlegger.BootleggerClient.CurrentEvent.topics.ToList(), media); } rv.SetAdapter(chips); FindViewById(Resource.Id.videometadata).Visibility = ViewStates.Gone; } FindViewById <ImageView>(Resource.Id.imageplayer).SetImageDrawable(null); try { FindViewById <TextView>(Resource.Id.metadata).Text = media.meta.shot_ex["name"].ToString() + " at " + media.meta.role_ex["name"].ToString() + " during " + media.meta.phase_ex["name"].ToString(); } catch { FindViewById <TextView>(Resource.Id.metadata).Text = ""; } try { FindViewById <TextView>(Resource.Id.timemeta).Text = media.CreatedAt.LocalizeFormat("ha E d MMM yy"); } catch { FindViewById <TextView>(Resource.Id.timemeta).Text = media.Static_Meta["captured_at"].ToString(); } FindViewById <TextView>(Resource.Id.description).Visibility = ViewStates.Gone; switch (media.MediaType) { case Shot.ShotTypes.VIDEO: case Shot.ShotTypes.AUDIO: //FindViewById<View>(Resource.Id.videoplayer).Visibility = ViewStates.Visible; try { //set other fields: string url = await Bootlegger.BootleggerClient.GetVideoUrl(media); if (url.StartsWith("file://")) { DefaultDataSourceFactory httpDataSourceFactory = new DefaultDataSourceFactory(this, "BootleggerPreview"); var extractorsFactory = new DefaultExtractorsFactory(); mediaSource = new ExtractorMediaSource(Android.Net.Uri.Parse(url), httpDataSourceFactory, extractorsFactory, null, null); } else { var client = new OkHttpClient.Builder() .Cache((Application as BootleggerApp).FilesCache) .Build(); OkHttpDataSourceFactory httpDataSourceFactory = new OkHttpDataSourceFactory(client, "BootleggerPreview"); var extractorsFactory = new DefaultExtractorsFactory(); mediaSource = new ExtractorMediaSource(Android.Net.Uri.Parse(url), httpDataSourceFactory, extractorsFactory, null, null); } _player.Prepare(mediaSource); } catch (Exception e) { //Toast.MakeText(this, Resource.String.cannotloadvideo, ToastLength.Short).Show(); LoginFuncs.ShowToast(this, e); } break; case Shot.ShotTypes.PHOTO: //FindViewById<View>(Resource.Id.videoplayer).Visibility = ViewStates.Gone; if (media.Status == MediaItem.MediaStatus.DONE && !string.IsNullOrEmpty(media.path)) { //string url = await (Application as BootleggerApp).Comms.(videofile); Picasso.With(this).Load(media.Thumb + "?s=300").Fit().CenterInside().Into(FindViewById <ImageView>(Resource.Id.imageplayer)); } else { Picasso.With(this).Load("file://" + media.Filename).Fit().CenterInside().Into(FindViewById <ImageView>(Resource.Id.imageplayer)); } break; } }
public IDataSourceFactory BuildDataSourceFactory(ITransferListener listener) { DefaultDataSourceFactory upstreamFactory = new DefaultDataSourceFactory(Context, listener, BuildHttpDataSourceFactory(listener)); return(BuildReadOnlyCacheDataSource(upstreamFactory, null)); }