private async void AddFilesFromDisk(object parameter) { this.Idle = false; var fileOpenPicker = new FileOpenPicker(); fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fileOpenPicker.FileTypeFilter.Add(".png"); fileOpenPicker.FileTypeFilter.Add(".jpg"); fileOpenPicker.FileTypeFilter.Add(".jpeg"); fileOpenPicker.FileTypeFilter.Add(".mp4"); fileOpenPicker.FileTypeFilter.Add(".avi"); fileOpenPicker.FileTypeFilter.Add(".mpg"); var selectedFiles = await fileOpenPicker.PickMultipleFilesAsync(); var alreadySetSelectedMediaItem = false; foreach (var selectedFile in selectedFiles) { var fileName = string.Format("{0}-{1}{2}", Path.GetFileNameWithoutExtension(selectedFile.Name), Guid.NewGuid(), Path.GetExtension(selectedFile.Name)); var localFile = await selectedFile.CopyAsync(_localMediaFolder, fileName); var mediaItem = new MediaItem(FolderType.Local, ReservationId, localFile.Name); MediaItems.Add(mediaItem); if (!alreadySetSelectedMediaItem) { SelectedMediaItem = mediaItem; alreadySetSelectedMediaItem = true; } } this.Idle = true; }
private async Task LoadMediaFiles() { MediaItems.Clear(); var localFiles = await _localMediaFolder.GetFilesAsync(); var localMediaItems = localFiles.Select(file => new MediaItem(FolderType.Local, ReservationId, file.Name)); foreach (var mediaItem in localMediaItems) { MediaItems.Add(mediaItem); } UpdateOperationsCount(+1); var files = await _data.GetAzureStorageFilesByTrip(ReservationId); foreach (var fileMetadata in files) { StorageFile destinationFile = await _tempMediaFolder.CreateFileAsync(fileMetadata.FileName, CreationCollisionOption.ReplaceExisting); await _transferManager.DownloadAsync(fileMetadata.Uri, destinationFile); var mediaItem = new MediaItem(FolderType.Temp, ReservationId, fileMetadata.FileName); MediaItems.Add(mediaItem); } UpdateOperationsCount(-1); }
private async void CaptureVideo(object parameter) { if (!await VerifyCameraAvailable()) { return; } try { CameraCaptureUI dialog = new CameraCaptureUI(); dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video); if (file != null) { var fileName = string.Format("Video-{0}.mp4", Guid.NewGuid()); await file.MoveAsync(_localMediaFolder, fileName, NameCollisionOption.GenerateUniqueName); var mediaItem = new MediaItem(FolderType.Local, ReservationId, file.Name); MediaItems.Add(mediaItem); SelectedMediaItem = mediaItem; } } catch (Exception ex) { ShowFatalErrorMessageDialog(ResourceHelper.ResourceLoader.GetString("CaptureVideo"), ResourceHelper.ResourceLoader.GetString("CaptureVideoError")); } }
/// <summary> /// Performs any necessary housekeeping before playback /// </summary> protected virtual void Prepare() { if (QueueItem && !PlaybackController.IsPlaying) { QueueItem = false; // This is for music GoFullScreen = false; } // Always force this to false regardless of what the caller asks for if (QueueItem) { PlayIntros = false; } // Filter for IsPlaylistCapable if (MediaItems.Count() > 1) { // First filter out items that can't be queued in a playlist _MediaItems = GetPlaylistCapableItems(MediaItems); } if (Shuffle) { ShufflePlayableItems(); } PlaybackStartTime = DateTime.Now; }
public ActionResult MediaGalleriesDelete(string deleteId) { MediaGalleries mediaGalleries = new MediaGalleries(); switch (mediaGalleries.Delete(deleteId)) { case 0: MediaItems mediaItems = new MediaItems(); mediaItems.ForceCache(); ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyDeleted); break; case 2: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist); break; case 3: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemUsedSomewhereElse); break; default: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError); break; } return(RedirectToAction("MediaGalleries")); }
/// <summary> /// Performs any necessary housekeeping before playback /// </summary> protected virtual void Prepare() { if (QueueItem && !PlaybackController.IsPlaying) { QueueItem = false; // This is for music GoFullScreen = false; UseCustomPlayer = false; } // Filter for IsPlaylistCapable if (MediaItems.Count() > 1) { // First filter out items that can't be queued in a playlist _MediaItems = GetPlaylistCapableItems(MediaItems); } if (Shuffle) { ShufflePlayableItems(); } PlaybackStartTime = DateTime.Now; }
/// <summary> /// Goes through each Media object within PlayableMediaItems and updates Playstate for each individually /// </summary> private void UpdatePlayStates(BasePlaybackController controller, PlaybackStateEventArgs args) { string currentFile = CurrentFile; for (int i = 0; i < MediaItems.Count(); i++) { Media media = MediaItems.ElementAt(i); bool isCurrentMedia = i == CurrentMediaIndex; long currentPositionTicks = 0; int currentPlaylistPosition = 0; if (isCurrentMedia) { // If this is where playback is, update position and playlist currentPlaylistPosition = controller.GetPlayableFiles(media).ToList().IndexOf(currentFile); media.PlaybackStatus.PositionTicks = currentPositionTicks = args.Position; } Application.CurrentInstance.UpdatePlayState(media, media.PlaybackStatus, controller.IsPaused, EnablePlayStateSaving); if (isCurrentMedia) { break; } } HasUpdatedPlayState = true; }
private void SetMediaItem(ref System.Web.UI.SilverlightControls.MediaPlayer SLP) { MediaItems mi = new MediaItems(); System.Web.UI.SilverlightControls.MediaChapter mc; try { // get Media item from XML mi.GetMediaItem(); // set Media source SLP.MediaSource = mi.MediaSource; SLP.PlaceholderSource = mi.PlaceholderSource; // add Chapters if (mi.Chapters.Count > 0) { for (int i = 0; i < mi.Chapters.Count; i++) { mc = new System.Web.UI.SilverlightControls.MediaChapter(); mc.Position = mi.Chapters[i].Position; mc.ThumbnailSource = mi.Chapters[i].ThumbnailSource; mc.Title = mi.Chapters[i].Title; SLP.Chapters.Add(mc); mc = null; } } } catch { } finally { mi = null; mc = null; } }
private void TruncateMediaItemsToMaxCount() { while (MediaItems.Count > _optionsService.Options.MaxItemCount) { MediaItems.RemoveAt(MediaItems.Count - 1); } }
private void ProcessMultiFilePath(List <string> multiFilePath, int mediaTtpeId, BackEndMediaItemsAdd backEndMediaItemsAdd) { MediaItems mediaItems = new MediaItems(); string allActiveLanguages = new Languages().GetAllLanguages(isActive: true).Select(i => i.LanguageCode).ToCSV('|'); foreach (string filePath in multiFilePath) { int?result = mediaItems.Add(backEndMediaItemsAdd.MediaGalleryCode, filePath, mediaTtpeId, backEndMediaItemsAdd.IsAllActive, allActiveLanguages); switch (result) { case 0: ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyAdded + ": " + filePath); break; case 2: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings_MediaGalleries.MediaItemAlreadyExists + ": " + filePath); break; default: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError + ": " + filePath); break; } } }
private void InsertBlankMediaItem() { // only add a "blank screen" item if we don't already display // a permanent black backdrop. if (!_optionsService.Options.PermanentBackdrop && _optionsService.Options.IncludeBlanksScreenItem) { var blankScreenPath = GetBlankScreenPath(); var item = new MediaItem { MediaType = _mediaProviderService.GetSupportedMediaType(blankScreenPath), Id = Guid.NewGuid(), IsBlankScreen = true, IsVisible = true, AllowFreezeCommand = _optionsService.Options.ShowFreezeCommand, CommandPanelVisible = _optionsService.Options.ShowMediaItemCommandPanel, Name = Properties.Resources.BLANK_SCREEN, FilePath = blankScreenPath, LastChanged = DateTime.UtcNow.Ticks }; MediaItems.Insert(0, item); _metaDataProducer.Add(item); } }
public void AddMedia(IEnumerable <Media> itemsToAdd) { List <Media> newList = MediaItems.ToList(); newList.AddRange(itemsToAdd); MediaItems = newList; }
private void SortMediaItems() { List <MediaItem> sorted = MediaItems.OrderBy(x => x.Name).ToList(); for (int n = 0; n < sorted.Count; ++n) { MediaItems.Move(MediaItems.IndexOf(sorted[n]), n); } }
private static void AddYmlItems(this Db db, List <DbItem> items, List <DbTemplate> templates, bool merge = false) { if (items != null && items.Count > 0) { db.AddRange(LayoutItems.Get(items), merge); db.AddRange(SystemItems.Get(items), merge); db.AddRange(MediaItems.Get(items), merge); db.AddRange(ContentItems.Get(items, templates), merge); } }
public MediaModel GetMedia(string id) { MediaModel media; if (!MediaItems.TryGetValue(id, out media)) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(media); }
/// <summary> /// Plays all media items currently dislayed in the view, starting with the selected media item /// </summary> private void PlayFromHere() { for (int i = 0; i < MediaItems.Count; i++) { if (MediaItems[i] == SelectedMediaItem) { OnPlayMediaItems(MediaItems.ToArray(), i); break; } } }
private async Task UploadMedia(bool isPrivate) { if (SelectedMediaItem == null) { var msg = new MessageDialog(ResourceHelper.ResourceLoader.GetString("SelectMediaFileToUpload")); await msg.ShowAsync(); return; } if (SelectedMediaItem.FolderType == FolderType.Temp) { var msg = new MessageDialog(ResourceHelper.ResourceLoader.GetString("MediaItemHasAlreadyBeenUploaded")); await msg.ShowAsync(); return; } UpdateOperationsCount(+1); var fileName = SelectedMediaItem.Name; MediaItems.Remove(SelectedMediaItem); SelectedMediaItem = null; var file = await _localMediaFolder.GetFileAsync(fileName); await _transferManager.UploadAsync(file, TravelerInfo.TravelerId, null, ReservationId, isPrivate); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); StorageFile tempFile = null; try { tempFile = await file.CopyAsync(_tempMediaFolder, file.Name, NameCollisionOption.GenerateUniqueName); await file.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch (Exception exc) { ShowFatalErrorMessageDialog(exc.Message, string.Empty); } if (tempFile != null) { var mediaItem = new MediaItem(FolderType.Temp, ReservationId, tempFile.Name); MediaItems.Add(mediaItem); SelectedMediaItem = mediaItem; } UpdateOperationsCount(-1); }
public MediaModel PutMedia(string id) { MediaModel media; if (!MediaItems.TryGetValue(id, out media)) { throw new HttpResponseException(HttpStatusCode.NotFound); } // TODO: Update the image here... return(media); }
public bool IsFileUsed(string filePath) { bool result = false; MediaItems mediaItems = new MediaItems(); if (mediaItems.IsNotNull()) { result = mediaItems.IsFileUsed(filePath); } return(result); }
private void TrackDownloadCompleted(TrackDownloadEventArgs e) { ProgressStatus.TrackDownloadStatus = e.Status.GetDescription(); if (TrackStatus.DownloadSkipped == e.Status) { MediaItems.UpdateTrackViewItem(e.TrackFile.Track, e.TrackFile.Track.IsDownloadable); } else { MediaItems.UpdateTrackViewItem(e.TrackFile.Track, TrackStatus.DownloadCompleted == e.Status); } }
private void LoadMediaItemsInternal() { var files = _mediaProviderService.GetMediaFiles(); var sourceFilePaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var destFilePaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var file in files) { sourceFilePaths.Add(file.FullPath); } var itemsToRemove = new List <MediaItem>(); foreach (var item in MediaItems) { if (!sourceFilePaths.Contains(item.FilePath)) { // remove this item. itemsToRemove.Add(item); } destFilePaths.Add(item.FilePath); } // remove old items. foreach (var item in itemsToRemove) { MediaItems.Remove(item); } // add new items. foreach (var file in files) { if (!destFilePaths.Contains(file.FullPath)) { var item = CreateNewMediaItem(file); MediaItems.Add(item); _metaDataProducer.Add(item); } } SortMediaItems(); TruncateMediaItemsToMaxCount(); _hiddenMediaItemsService.Init(MediaItems); _frozenVideosService.Init(MediaItems); InsertBlankMediaItem(); }
/// <summary> /// Adds media items to the playlist /// </summary> /// <param name="mediaItems">Media items being added to the playlist</param> public void AddMediaItems(IEnumerable <MediaItem> mediaItems) { PlayStateEnum previousPlayState = PlayState; foreach (MediaItem mediaItem in mediaItems) { MediaItems.Add(mediaItem); } if (previousPlayState == PlayStateEnum.Stopped) { Stop(); } }
/// <summary> /// Deletes the media items from the database /// </summary> /// <param name="mediaItems">Media items being deleted</param> private void DeleteMediaItems(MediaItem[] mediaItems) { foreach (MediaItem mediaItem in mediaItems) { if (RecycleBinPrompt) { mediaItem.Delete(); } MediaItems.Remove(mediaItem); } OnMediaItemsDeleted(mediaItems); }
public ActionResult MediaItemsEdit(BackEndMediaItemsList backEndMediaItemsList, string id) { if (ModelState.IsValidOrRefresh()) { MediaItems mediaItems = new MediaItems(); foreach (MediaItem mediaItem in backEndMediaItemsList.MediaItemsList) { if (mediaItem.IsMarkedForDeletion) { switch (mediaItems.Delete(mediaItem.MediaItemId)) { case 0: ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyDeleted + ": " + mediaItem.MediaItemId); break; case 2: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist + ": " + mediaItem.MediaItemId); break; case 3: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemUsedSomewhereElse + ": " + mediaItem.MediaItemId); break; default: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError + ": " + mediaItem.MediaItemId); break; } } else { switch (mediaItems.Edit(mediaItem.MediaItemId, (backEndMediaItemsList.SelectedIsMainItem == mediaItem.MediaItemId), mediaItem.Ordering, mediaItem.IsActive, GetLanguageCodesMediaTitles(mediaItem.MediaItemLanguagesTitles))) { case 0: ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyEdited + ": " + mediaItem.MediaItemId); break; case 2: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist + ": " + mediaItem.MediaItemId); break; default: ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError + ": " + mediaItem.MediaItemId); break; } } } } return(RedirectToAction("MediaItems", new { id = id })); }
public async Task <HttpResponseMessage> PostMedia() { //// Check if there is anything inside the message body if (Request.Content != null && Request.Content.Headers.ContentLength > 0) { // TODO: Try to solve the retrieval problem with a custom // Parameter Binding impl. // GIANT_NOTE: Don't do this like below at home. Guid id = Guid.NewGuid(); string contentType = Request.Content.Headers.ContentType.MediaType; string extension = GetExtension(contentType); string path = "app_files"; string appPath = HostingEnvironment.ApplicationPhysicalPath; string dirPath = string.Concat(appPath, "\\", path); string fileName = string.Concat(id.ToString(), extension); string fullFileName = string.Concat(dirPath, "\\", fileName); Uri selfLink = new Uri(Url.Link("DefaultApi", new { controller = "media", id = id })); Uri contentLink = new Uri(string.Concat(Request.RequestUri.GetLeftPart(UriPartial.Authority), "/", path, "/", fileName)); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } using (Stream contentStream = await Request.Content.ReadAsStreamAsync()) using (FileStream fileStream = File.Create(fullFileName)) { contentStream.Seek(0, SeekOrigin.Begin); await contentStream.CopyToAsync(fileStream); } var mediaModel = new MediaModel { Id = id.ToString(), // AuthorName = "Tugberk", // Title = "Awesome Pic Title...", // Summary = "Awesome Pic Summary...", ImageUrl = contentLink, ContentType = contentType, LastUpdated = DateTime.UtcNow }; MediaItems.TryAdd(id.ToString(), mediaModel); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, mediaModel); response.Headers.Location = selfLink; return(response); } return(Request.CreateResponse(HttpStatusCode.Conflict)); }
private void SortMediaItems() { List<MediaItem> sorted = MediaItems.OrderBy(x => x.AlphaNumericName).ToList(); var blank = sorted.SingleOrDefault(x => x.IsBlankScreen); if (blank != null && blank != sorted.First()) { sorted.Remove(blank); sorted.Insert(0, blank); } for (int n = 0; n < sorted.Count; ++n) { MediaItems.Move(MediaItems.IndexOf(sorted[n]), n); } }
/// <summary> /// Shuffles the list of playable items /// </summary> private void ShufflePlayableItems() { Random rnd = new Random(); // If playback is based on Media objects if (HasMediaItems) { MediaItems = MediaItems.OrderBy(i => rnd.Next()).ToList(); } else { // Otherwise if playback is based on a list of files Files = Files.OrderBy(i => rnd.Next()).ToList(); } }
protected override void GenerateMediaFiles() { var mediaFolder = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "Media"); Directory.CreateDirectory(MediaFolder); foreach (var artItem in ArtItem.ArtItems) { var sourceFile = Path.Combine(mediaFolder, artItem.FileName); var destinationFile = Path.Combine(MediaFolder, artItem.FileName); File.Copy(sourceFile, destinationFile, true); var mediaItem = new MediaItem(artItem, destinationFile); MediaItems.Add(mediaItem); } }
private void btnBrowse_Click(object sender, RoutedEventArgs e) { Button btnBrowse = sender as Button; MediaItem missingMediaItem = btnBrowse.DataContext as MediaItem; CancelMediaItemsOperationEventArgs cmioea = new CancelMediaItemsOperationEventArgs(new MediaItem[1] { missingMediaItem }); OnBrowse(cmioea); if (!cmioea.Cancel) { MediaItems = MediaItems.Where(p => !p.IsInDatabase); } }
internal void Play() { if (Microsoft.MediaCenter.UI.Application.ApplicationThread != System.Threading.Thread.CurrentThread) { Application.UIDeferredInvokeIfRequired(() => Play()); return; } System.Diagnostics.Debug.Assert(Microsoft.MediaCenter.UI.Application.ApplicationThread == Thread.CurrentThread); Prepare(); if (!MediaItems.Any() && !Files.Any()) { Microsoft.MediaCenter.MediaCenterEnvironment ev = Application.MediaCenterEnvironment; ev.Dialog(Application.CurrentInstance.StringData("NoContentDial"), Application.CurrentInstance.StringData("Playstr"), Microsoft.MediaCenter.DialogButtons.Ok, 500, true); return; } if (CurrentMedia != null) { Logger.ReportInfo(string.Format("{0} about to play {1}({2}) ", PlaybackController.ControllerName, DisplayName, CurrentMedia.Files.FirstOrDefault())); } // If the controller already has active playable items, stop it and wait for it to flush out if (!QueueItem) { PlaybackController.StopAndWait(); } // Run all pre-play processes RunPrePlayProcesses(); if (!QueueItem && StopAllPlaybackBeforePlaying) { StopAllApplicationPlayback(); } if (UseAutoPlay) { Logger.ReportVerbose("Playing with autoplay. Marking watched since we have no way of getting status on this."); MarkWatchedIfNeeded(); } else { //AdjustRefreshRate(); PlaybackController.Play(this); } }