예제 #1
0
        public ActionResult GetSuggestedWeatherStationByGeocoordinates(double latitude, double longitude)
        {
            ActionResult         actionResult;
            DegreeDaysApi        degreeDaysApi       = new DegreeDaysApi(new AccountKey(this.apiKey_degreeDaysAccountKey), new SecurityKey(this.apiKey_degreeDaysSecurityKey));
            DatedDataSpec        datedDataSpec       = DataSpec.Dated(Calculation.HeatingDegreeDays(Temperature.Fahrenheit(65)), DatedBreakdown.Daily(Period.LatestValues(10)));
            LocationDataRequest  locationDataRequest = new LocationDataRequest(Location.LongLat(new LongLat(longitude, latitude)), new DataSpecs(new DataSpec[] { datedDataSpec }));
            LocationDataResponse locationData        = null;

            try
            {
                locationData = degreeDaysApi.DataApi.GetLocationData(locationDataRequest);
                if (locationData == null)
                {
                    return(base.Json(new MvcAjaxResponse(new ErrorInfo("We're sorry we could not find the suggested weather station for the coordinates provided."), false)));
                }
                if (locationData.StationId.ToString().Length > 0)
                {
                    return(base.Json(new MvcAjaxResponse(locationData.StationId.ToString())));
                }
                return(base.Json(new MvcAjaxResponse(new ErrorInfo("We're sorry we could not find the suggested weather station for the coordinates provided (response was blank)."), false)));
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                actionResult = base.Json(new MvcAjaxResponse(new ErrorInfo(exception.Message), false));
            }
            return(actionResult);
        }
            protected override List <SampleGroup> RunInBackground(params string[] @params)
            {
                var result     = new List <SampleGroup>();
                var userAgent  = Util.Util.GetUserAgent(context, "ExoPlayerDemo");
                var dataSource = new DefaultDataSource(context, null, userAgent, false);

                foreach (var uri in @params)
                {
                    var dataSpec    = new DataSpec(global::Android.Net.Uri.Parse(uri));
                    var inputStream = new DataSourceInputStream(dataSource, dataSpec);
                    var memory      = new MemoryStream();
                    var buffer      = new byte[1024];
                    int read;
                    while ((read = inputStream.Read(buffer)) > 0)
                    {
                        memory.Write(buffer, 0, read);
                    }
                    memory.Seek(0, SeekOrigin.Begin);

                    try
                    {
                        ReadSampleGroups(new JsonReader(new InputStreamReader(memory, "UTF-8")), result);
                    }
                    catch (System.Exception e)
                    {
                        Log.Error(TAG, "Error loading sample list: " + uri, e);
                        sawError = true;
                    }
                    finally
                    {
                        Util.Util.CloseQuietly(dataSource);
                    }
                }
                return(result);
            }
예제 #3
0
 public void OnLoadError(DataSpec dataSpec, int dataType, int trackType, Format trackFormat,
                         int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
                         long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded,
                         IOException error, bool wasCanceled)
 {
     printInternalError("loadError", error);
 }
예제 #4
0
        public ActionResult ValidateWeatherStationByStationId(string stationId)
        {
            ActionResult         actionResult;
            DegreeDaysApi        degreeDaysApi       = new DegreeDaysApi(new AccountKey(this.apiKey_degreeDaysAccountKey), new SecurityKey(this.apiKey_degreeDaysSecurityKey));
            DatedDataSpec        datedDataSpec       = DataSpec.Dated(Calculation.HeatingDegreeDays(Temperature.Fahrenheit(65)), DatedBreakdown.Daily(Period.LatestValues(10)));
            LocationDataRequest  locationDataRequest = new LocationDataRequest(Location.StationId(stationId), new DataSpecs(new DataSpec[] { datedDataSpec }));
            LocationDataResponse locationData        = null;

            try
            {
                locationData = degreeDaysApi.DataApi.GetLocationData(locationDataRequest);
                if (locationData == null)
                {
                    return(base.Json(new MvcAjaxResponse(new ErrorInfo(string.Concat("We're sorry we could not validate the weather station ", stationId, ".")), false)));
                }
                if (locationData.StationId.ToString().Length > 0)
                {
                    return(base.Json(new MvcAjaxResponse(locationData.StationId.ToString())));
                }
                return(base.Json(new MvcAjaxResponse(new ErrorInfo(string.Concat("We're sorry we could not validate the weather station ", stationId, " (response was blank).")), false)));
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                actionResult = base.Json(new MvcAjaxResponse(new ErrorInfo(exception.Message), false));
            }
            return(actionResult);
        }
예제 #5
0
        public override BaseElement Clone()
        {
            DataSpec clone = new DataSpec
            {
                Values = this
            };

            return(clone);
        }
예제 #6
0
        public long Open(DataSpec p0)
        {
            if (this._isOpened)
            {
                this.Close();
            }

            this.Uri = p0.Uri.ToString();
            this._rtmpClient = new RtmpClient();
            this._rtmpClient.Open(p0.Uri.ToString(), false);
            this._isOpened = true;
            return C.LengthUnbounded;
        }
예제 #7
0
        private void CacheVideosFiles(Uri videoUrl)
        {
            try
            {
                if (Cache == null)
                {
                    Cache = new SimpleCache(MainContext.CacheDir, new NoOpCacheEvictor());
                }

                if (CacheDataSourceFactory == null)
                {
                    CacheDataSourceFactory = new CacheDataSourceFactory(Cache, DefaultDataSourceFac);
                }

                var dataSpec = new DataSpec(videoUrl, 0, 3000 * 1024, null); //0, 1000 * 1024, null
                var counters = new CacheUtil.CachingCounters();

                CacheUtil.GetCached(dataSpec, Cache, counters);

                if (counters.ContentLength == counters.TotalCachedBytes())
                {
                }
                else if (counters.TotalCachedBytes() == 0)
                {
                    // not cached at all
                    Task.Run(() =>
                    {
                        try
                        {
                            var cacheDataSource = new CacheDataSource(Cache, CacheDataSourceFactory.CreateDataSource());
                            CacheUtil.Cache(dataSpec, Cache, cacheDataSource, counters, new AtomicBoolean());
                            double downloadPercentage = counters.TotalCachedBytes() * 100d / counters.ContentLength;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    });
                }
                else
                {
                    // just few mb cached
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #8
0
 public void OnAdLoadError(AdsMediaSource.AdLoadException error, DataSpec dataSpec)
 {
 }
예제 #9
0
 public void OnAdLoadError(AdsMediaSource.AdLoadException p0, DataSpec p1)
 {
 }
예제 #10
0
        public void PlayVideo(bool isEndOfList, Holders.VideoAdapterViewHolder holderVideoPlayer = null, PostsObject item = null)
        {
            try
            {
                if (VideoPlayer == null)
                {
                    SetPlayer();
                }

                int targetPosition;
                if (!isEndOfList)
                {
                    var startPosition = ((LinearLayoutManager)GetLayoutManager()).FindFirstVisibleItemPosition();
                    var endPosition   = ((LinearLayoutManager)GetLayoutManager()).FindLastVisibleItemPosition();

                    if (endPosition - startPosition > 1)
                    {
                        endPosition = startPosition + 1;
                    }

                    if (startPosition < 0 || endPosition < 0)
                    {
                        return;
                    }

                    if (startPosition != endPosition)
                    {
                        var startPositionVideoHeight = GetVisibleVideoSurfaceHeight(startPosition);
                        var endPositionVideoHeight   = GetVisibleVideoSurfaceHeight(endPosition);
                        targetPosition = startPositionVideoHeight > endPositionVideoHeight ? startPosition : endPosition;
                    }
                    else
                    {
                        targetPosition = startPosition;
                    }
                }
                else
                {
                    targetPosition = GetAdapter().ItemCount - 1;
                }


                if (targetPosition == PlayPosition)
                {
                    return;
                }

                // set the position of the list-item that is to be played
                PlayPosition = targetPosition;
                if (VideoSurfaceView == null)
                {
                    return;
                }

                VideoSurfaceView.Visibility = ViewStates.Invisible;
                RemoveVideoView(VideoSurfaceView);

                var currentPosition = targetPosition - ((LinearLayoutManager)GetLayoutManager()).FindFirstVisibleItemPosition();

                var child = GetChildAt(currentPosition);
                if (child == null)
                {
                    return;
                }

                dynamic holder;
                if (holderVideoPlayer != null)
                {
                    holder         = holderVideoPlayer;
                    targetPosition = holderVideoPlayer.LayoutPosition;
                }
                else
                {
                    Holders.VideoAdapterViewHolder holderChild = (Holders.VideoAdapterViewHolder)child.Tag;
                    if (holderChild == null)
                    {
                        PlayPosition = -1;
                        return;
                    }
                    else
                    {
                        targetPosition = holderChild.LayoutPosition;
                        holder         = holderChild;
                    }
                }

                if (!(holder is Holders.VideoAdapterViewHolder holderVideo))
                {
                    return;
                }
                MediaContainerLayout = holderVideo.MediaContainerLayout;
                Thumbnail            = holderVideo.VideoImage;


                ViewHolderParent = holderVideo.ItemView;
                PlayControl      = holderVideo.PlayControl;

                if (!IsVideoViewAdded)
                {
                    AddVideoView();
                }
                holderVideo.VideoProgressBar.Visibility = ViewStates.Visible;
                VideoSurfaceView.Player = VideoPlayer;

                var controlView = VideoSurfaceView.FindViewById <PlayerControlView>(Resource.Id.exo_controller);
                Uri videoUrl    = Uri.Parse(item != null ? item.MediaSet[0].File : NativeFeedAdapter.PixelNewsFeedList[targetPosition].MediaSet[0].File);

                //>> Old Code
                //===================== Exo Player ========================
                var lis = new ExoPlayerRecyclerEvent(controlView, this, holderVideo);

                IMediaSource videoSource = GetMediaSourceFromUrl(videoUrl, "normal");

                var dataSpec = new DataSpec(videoUrl); //0, 1000 * 1024, null

                if (Cache == null)
                {
                    CacheVideosFiles(videoUrl);
                }

                //Cache = new SimpleCache(new Java.IO.File(MainContext.FilesDir, "media"), new NoOpCacheEvictor());

                if (CacheDataSourceFactory == null)
                {
                    CacheDataSourceFactory = new CacheDataSourceFactory(Cache, DefaultDataSourceFac);
                }

                var counters = new CacheUtil.CachingCounters();

                CacheUtil.GetCached(dataSpec, Cache, counters);
                if (counters.ContentLength == counters.TotalCachedBytes())
                {
                    videoSource = new ExtractorMediaSource.Factory(CacheDataSourceFactory).CreateMediaSource(videoUrl);
                }
                else if (counters.TotalCachedBytes() == 0)
                {
                    videoSource = new ExtractorMediaSource.Factory(CacheDataSourceFactory).CreateMediaSource(videoUrl);
                    // not cached at all
                    Task.Run(() =>
                    {
                        try
                        {
                            var cacheDataSource = new CacheDataSource(Cache, CacheDataSourceFactory.CreateDataSource());
                            CacheUtil.Cache(dataSpec, Cache, cacheDataSource, counters, new AtomicBoolean());
                            double downloadPercentage = counters.TotalCachedBytes() * 100d / counters.ContentLength;
                            Console.WriteLine(downloadPercentage);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    });
                }
                else
                {
                    // partially cached
                    videoSource = new ExtractorMediaSource.Factory(CacheDataSourceFactory).CreateMediaSource(videoUrl);
                }

                lis.mFullScreenButton.SetOnClickListener(new NewClicker(lis.mFullScreenButton, videoUrl.ToString(), this));

                VideoPlayer.Prepare(videoSource);
                VideoPlayer.AddListener(lis);
                VideoPlayer.PlayWhenReady = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        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();
            }
        }
 public void OnLoadCanceled(DataSpec p0, int p1, int p2, Format p3, int p4, Java.Lang.Object p5, long p6, long p7, long p8, long p9, long p10)
 {
 }
예제 #13
0
 public void OnLoadStarted(DataSpec p0, int p1, int p2, Format p3, int p4, Object p5, long p6, long p7, long p8)
 {
 }
예제 #14
0
 public void OnLoadError(DataSpec p0, int p1, int p2, Format p3, int p4, Object p5, long p6, long p7, long p8, long p9, long p10, IOException p11, bool p12)
 {
 }
예제 #15
0
 public void OnLoadCompleted(DataSpec p0, int p1, int p2, Format p3, int p4, Object p5, long p6, long p7, long p8, long p9, long p10)
 {
 }
예제 #16
0
 public void OnLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat,
                             int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
                             long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded)
 {
     // Do nothing.
 }
예제 #17
0
        // AdaptiveMediaSourceEventListener

        public void OnLoadStarted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat,
                                  int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs,
                                  long mediaEndTimeMs, long elapsedRealtimeMs)
        {
            // Do nothing.
        }
예제 #18
0
        public override void ParseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        {
            if (!(parentElement is Activity) && !(parentElement is Process))
            {
                return;
            }

            IOSpecification ioSpecification = new IOSpecification();

            BpmnXMLUtil.AddXMLLocation(ioSpecification, xtr);
            bool readyWithIOSpecification = false;

            try
            {
                while (!readyWithIOSpecification && xtr.HasNext())
                {
                    //xtr.next();

                    if (xtr.IsStartElement() && BpmnXMLConstants.ELEMENT_DATA_INPUT.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        DataSpec dataSpec = new DataSpec();
                        BpmnXMLUtil.AddXMLLocation(dataSpec, xtr);
                        dataSpec.Id             = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID);
                        dataSpec.Name           = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_NAME);
                        dataSpec.ItemSubjectRef = ParseItemSubjectRef(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ITEM_SUBJECT_REF), model);
                        ioSpecification.DataInputs.Add(dataSpec);
                    }
                    else if (xtr.IsStartElement() && BpmnXMLConstants.ELEMENT_DATA_OUTPUT.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        DataSpec dataSpec = new DataSpec();
                        BpmnXMLUtil.AddXMLLocation(dataSpec, xtr);
                        dataSpec.Id             = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID);
                        dataSpec.Name           = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_NAME);
                        dataSpec.ItemSubjectRef = ParseItemSubjectRef(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ITEM_SUBJECT_REF), model);
                        ioSpecification.DataOutputs.Add(dataSpec);
                    }
                    else if (xtr.IsStartElement() && BpmnXMLConstants.ELEMENT_DATA_INPUT_REFS.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        string dataInputRefs = xtr.ElementText;
                        if (!string.IsNullOrWhiteSpace(dataInputRefs))
                        {
                            ioSpecification.DataInputRefs.Add(dataInputRefs.Trim());
                        }
                    }
                    else if (xtr.IsStartElement() && BpmnXMLConstants.ELEMENT_DATA_OUTPUT_REFS.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        string dataOutputRefs = xtr.ElementText;
                        if (!string.IsNullOrWhiteSpace(dataOutputRefs))
                        {
                            ioSpecification.DataOutputRefs.Add(dataOutputRefs.Trim());
                        }
                    }
                    else if (xtr.EndElement && ElementName.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        readyWithIOSpecification = true;
                    }

                    if (xtr.IsEmptyElement && ElementName.Equals(xtr.LocalName, StringComparison.OrdinalIgnoreCase))
                    {
                        readyWithIOSpecification = true;
                    }
                }
            }
            catch (Exception e)
            {
                log.LogWarning(e, "Error parsing ioSpecification child elements");
            }

            if (parentElement is Process)
            {
                ((Process)parentElement).IoSpecification = ioSpecification;
            }
            else
            {
                ((Activity)parentElement).IoSpecification = ioSpecification;
            }
        }