Beispiel #1
0
        public MediaFile(string alias, string fileName, MediaFileType fileType)
        {
            // if opening a media file directly, make a copy of it first, to allow multiple instances
            if (!IsTempFile)
            {
                _tmpFileName = SaveFileToTmpDir(fileName);
            }

            // if the alias already exists, remove the old MediaFile and replace it with this
            if (_mediaFiles.ContainsKey(alias))
            {
                _mediaFiles[alias].Dispose();
            }

            // add this new MediaFile to static list
            _mediaFiles.Add(alias, this);

            Alias    = alias;
            FileName = fileName;
            FileType = fileType;

            IsPlaying = false;
            IsPaused  = false;

            Open();
        }
        private void SetCurrentPlayer(MediaFileType fileType)
        {
            if (_currentPlaybackManager != null)
            {
                RemoveEventHandlers();
            }
            switch (fileType)
            {
            case MediaFileType.AudioUrl:
            case MediaFileType.AudioFile:
                _currentPlaybackManager = AudioPlayer;
                break;

            case MediaFileType.VideoUrl:
            case MediaFileType.VideoFile:
                _currentPlaybackManager = VideoPlayer;
                break;

            case MediaFileType.Other:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            AddEventHandlers();
        }
Beispiel #3
0
 public FileElement(string caption, MediaFileType fileType, fileElementTapHandler handler) : base(caption)
 {
     Tapped += delegate {
         handler(Path, FileType);
     };
     FileType = fileType;
 }
Beispiel #4
0
        private string OpenFileType(MediaFileType fileType, out EngineResourceFileTypes resFileType)
        {
            switch (fileType)
            {
            case MediaFileType.wav:
                resFileType = EngineResourceFileTypes.Audio;
                return("waveaudio");

            case MediaFileType.mid:
            case MediaFileType.midi:
                resFileType = EngineResourceFileTypes.Audio;
                return("sequencer");

            case MediaFileType.wma:             // audio
            case MediaFileType.mp3:             // audio
                resFileType = EngineResourceFileTypes.Audio;
                return("mpegvideo");

            case MediaFileType.avi:             // video
            case MediaFileType.ogg:             // video
            case MediaFileType.mpg:             // video
            case MediaFileType.mpeg:            // video
            case MediaFileType.wmv:             // video
            case MediaFileType.asx:             // video
            case MediaFileType.unknown:         // assume video
            default:
                resFileType = EngineResourceFileTypes.Video;
                return("mpegvideo");
            }
        }
Beispiel #5
0
        public SelectFileForm(MediaFileType mediaFileType)
        {
            InitializeComponent();
            this.listView.FolderName = Service.Sdsite.CurrentDocument.Resources.AbsoluteFilePath;
            initFilter();
            FileType  = mediaFileType;
            filePaths = new List <SimpleExIndexXmlElement>();
            filePaths.Add(Service.Sdsite.CurrentDocument.Resources);
            pathNum++;
            listView.MultiSelect               = false;
            listView.SmallImageList            = new ImageList();
            listView.SmallImageList.ColorDepth = ColorDepth.Depth32Bit;

            backToolStripButton.Image      = ResourceService.GetResourceImage("selectResources.prior");
            preToolStripButton.Image       = ResourceService.GetResourceImage("selectResources.next");
            upToolStripButton.Image        = ResourceService.GetResourceImage("selectResources.up");
            newFolderToolStripButton.Image = ResourceService.GetResourceImage("selectResources.new");

            InitListView(Service.Sdsite.CurrentDocument.Resources);
            ContextMenuStrip SelectFileMemu = new ContextMenuStrip();

            importResourcesMenuItem = new ToolStripMenuItem("导入资源文件");
            SelectFileMemu.Items.Add(importResourcesMenuItem);
            listView.ContextMenuStrip        = SelectFileMemu;
            upToolStripButton.Enabled        = true;
            SelectFileMemu.ItemClicked      += new ToolStripItemClickedEventHandler(SelectFileMemu_ItemClicked);
            selectFileToolStrip.ItemClicked += new ToolStripItemClickedEventHandler(selectFileToolStrip_ItemClicked);
            preToolStripButton.Visible       = false;
            upToolStripButton.Enabled        = false;
        }
Beispiel #6
0
        /// <summary>
        /// 根据扩展名得到ITEM类型
        /// </summary>
        /// <param name="exfile"></param>
        /// <returns></returns>
        private MediaFileType GetListItemType(string exfile)
        {
            MediaFileType fileType = MediaFileType.None;

            if (String.IsNullOrEmpty(exfile))
            {
                return(fileType);
            }
            else if (_strImageType.Contains(exfile.ToLower()))
            {
                fileType = MediaFileType.Pic;
            }
            else if (_strFlash.Contains(exfile.ToLower()))
            {
                fileType = MediaFileType.Flash;
            }
            else if (_strAuto.Contains(exfile.ToLower()))
            {
                fileType = MediaFileType.Audio;
            }
            else if (_strVido.Contains(exfile.ToLower()))
            {
                fileType = MediaFileType.Video;
            }
            return(fileType);
        }
Beispiel #7
0
        public MediaBlobData GetBlobRequest(Media media, MediaFileType type)
        {
            switch (type)
            {
            case MediaFileType.Original:
                return(media.ToBlobDataRequest());

            case MediaFileType.WebPreview:
                return(new MediaBlobData
                {
                    Type = MediaBlobType.Web,
                    Filename = $"{media.Id.ToString("N")}.webp"
                });

            case MediaFileType.VideoGif:
                return(new MediaBlobData
                {
                    Type = MediaBlobType.VideoPreview,
                    Filename = $"{media.Id}.gif"
                });

            case MediaFileType.Video720:
                return(new MediaBlobData
                {
                    Type = MediaBlobType.VideoPreview,
                    Filename = $"720P_{media.Id}.mp4"
                });

            default:
                throw new ArgumentException($"Unknown type: {type}");
            }
        }
        public async Task Play(string url, MediaFileType fileType)
        {
            _loadMediaTaskCompletionSource = new TaskCompletionSource <bool>();
            try
            {
                if (_currentMediaSource != null)
                {
                    _currentMediaSource.StateChanged           -= MediaSourceOnStateChanged;
                    _currentMediaSource.OpenOperationCompleted -= MediaSourceOnOpenOperationCompleted;
                }
                // Todo: sync this with the playback queue
                var mediaPlaybackList = new MediaPlaybackList();
                _currentMediaSource = await CreateMediaSource(url, fileType);

                _currentMediaSource.StateChanged           += MediaSourceOnStateChanged;
                _currentMediaSource.OpenOperationCompleted += MediaSourceOnOpenOperationCompleted;
                var item = new MediaPlaybackItem(_currentMediaSource);
                mediaPlaybackList.Items.Add(item);
                _player.Source = mediaPlaybackList;
                _player.Play();
            }
            catch (Exception)
            {
                Debug.WriteLine("Unable to open url: " + url);
            }
        }
        private async Task <MediaSource> CreateMediaSource(string url, MediaFileType fileType)
        {
            switch (fileType)
            {
            case MediaFileType.AudioUrl:
            case MediaFileType.VideoUrl:
                return(MediaSource.CreateFromUri(new Uri(url)));

            case MediaFileType.AudioFile:
            case MediaFileType.VideoFile:
                var du          = _player.SystemMediaTransportControls.DisplayUpdater;
                var storageFile = await StorageFile.GetFileFromPathAsync(url);

                var playbackType = fileType == MediaFileType.AudioFile
                        ? MediaPlaybackType.Music
                        : MediaPlaybackType.Video;
                await du.CopyFromFileAsync(playbackType, storageFile);

                du.Update();
                return(MediaSource.CreateFromStorageFile(storageFile));

            case MediaFileType.Other:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);
            }
            return(MediaSource.CreateFromUri(new Uri(url)));
        }
Beispiel #10
0
        /// <summary>Saves a media file with metadata </summary>
        /// <param name="type">Type of media file to save.</param>
        /// <param name="filePath">Full path to a local file.</param>
        /// <returns>A task representing the asynchronous save operation.</returns>
        public static Task SaveAsync(MediaFileType type, string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
            {
                throw new ArgumentException(nameof(filePath));
            }

            return(PlatformSaveAsync(type, filePath));
        }
Beispiel #11
0
 /// <summary>
 /// Create a new SortMediaFile from a FileInfo object
 /// </summary>
 /// <param name="_file">FileInfo object to drop</param>
 public SortMediaFile(FileInfo _file)
 {
     FullFilePath   = _file.FullName;
     FileName       = _file.Name;
     FileSize       = _file.Length;
     FileCreated    = _file.CreationTime;
     Classification = MediaClassifications.Unclassified_File;
     FileType       = MediaFileType.
 }
        private MediaModel CreateMediaModel(Android.Net.Uri oUri)
        {
            MediaModel oModel = null;
            var        oType  = CrossCurrentActivity.Current.Activity.ContentResolver.GetType(oUri);

            var oPath = GetPathUri(oUri);

            if (oPath != null)
            {
                string        sPath          = string.Empty;
                string        sThumpnailPath = string.Empty;
                string        sFileName      = System.IO.Path.GetFileName(oPath);
                string        sExt           = System.IO.Path.GetExtension(oPath) ?? string.Empty;
                MediaFileType mediaFileType  = MediaFileType.Image;



                if (oType.StartsWith(Enum.GetName(typeof(MediaFileType), MediaFileType.Image), StringComparison.CurrentCultureIgnoreCase))
                {
                    var fullImage = ImageHelper.RotateImage(oPath, 1);

                    sPath = FileService.GetOutputPath(MediaFileType.Image, TempDir, $"{sFileName}{sExt}");
                    File.WriteAllBytes(sPath, fullImage);

                    var oThumpnailImg = ImageHelper.RotateImage(oPath, 0.25f);
                    sThumpnailPath = FileService.GetOutputPath(MediaFileType.Image, TempDir, $"{sFileName}-THUMBNAIL{sExt}");

                    File.WriteAllBytes(sThumpnailPath, oThumpnailImg);
                }
                else if (oType.StartsWith(Enum.GetName(typeof(MediaFileType), MediaFileType.Video), StringComparison.CurrentCultureIgnoreCase))
                {
                    sPath = oPath;
                    var bitmap = ThumbnailUtils.CreateVideoThumbnail(oPath, ThumbnailKind.MiniKind);

                    sThumpnailPath = FileService.GetOutputPath(MediaFileType.Image, TempDir, $"{sFileName}-THUMBNAIL{sExt}");
                    var stream = new FileStream(sThumpnailPath, FileMode.Create);
                    bitmap?.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                    stream.Close();

                    mediaFileType = MediaFileType.Video;
                }

                if (!string.IsNullOrEmpty(sPath) && !string.IsNullOrEmpty(sThumpnailPath))
                {
                    oModel = new MediaModel()
                    {
                        FilePath    = sPath,
                        MediaType   = mediaFileType,
                        PreviewFile = sThumpnailPath
                    };
                }
            }


            return(oModel);
        }
Beispiel #13
0
        /// <summary>Saves a media file with metadata </summary>
        /// <param name="type">Type of media file to save.</param>
        /// <param name="data">A byte array to save to the file.</param>
        /// <param name="fileName">The name of the saved file including the extension.</param>
        /// <returns>A task representing the asynchronous save operation.</returns>
        public static Task SaveAsync(MediaFileType type, byte[] data, string fileName)
        {
            if (!(data?.Length > 0))
            {
                throw new ArgumentNullException(nameof(data));
            }
            CheckFileName(fileName);

            return(PlatformSaveAsync(type, data, fileName));
        }
Beispiel #14
0
        /// <summary>Saves a media file with metadata </summary>
        /// <param name="type">Type of media file to save.</param>
        /// <param name="fileStream">The stream to output the file to.</param>
        /// <param name="fileName">The name of the saved file including the extension.</param>
        /// <returns>A task representing the asynchronous save operation.</returns>
        public static Task SaveAsync(MediaFileType type, Stream fileStream, string fileName)
        {
            if (fileStream == null)
            {
                throw new ArgumentNullException(nameof(fileStream));
            }
            CheckFileName(fileName);

            return(PlatformSaveAsync(type, fileStream, fileName));
        }
Beispiel #15
0
        static public string SelectResourceFormat(MediaFileType type, Form owmerForm)
        {
            string id = SelectResource(type, owmerForm);

            if (!string.IsNullOrEmpty(id))
            {
                return(Utility.Regex.FormatResourceId(id));
            }
            return(null);
        }
Beispiel #16
0
        public async Task <IActionResult> Get([FromRoute, Required] MediaFileType kind, [FromRoute, Required] int fileId, [FromRoute, Required] string language)
        {
            var subtitlePath = await _dispatcher.Dispatch(new SubtitlePathQuery(kind, fileId, language));

            if (!string.IsNullOrEmpty(subtitlePath))
            {
                return(PhysicalFile(subtitlePath, "text/vtt"));
            }
            return(NotFound());
        }
Beispiel #17
0
        MediaFile CreateMediaFileFromUri(Android.Net.Uri uri)
        {
            MediaFile mediaFile = null;
            var       type      = CrossCurrentActivity.Current.Activity.ContentResolver.GetType(uri);

            var path = GetRealPathFromURI(uri);

            if (path != null)
            {
                string        fullPath           = string.Empty;
                string        thumbnailImagePath = string.Empty;
                var           fileName           = System.IO.Path.GetFileNameWithoutExtension(path);
                var           ext           = System.IO.Path.GetExtension(path) ?? string.Empty;
                MediaFileType mediaFileType = MediaFileType.Image;
                var           imageTypeName = Enum.GetName(typeof(MediaFileType), MediaFileType.Image).ToLowerInvariant();
                var           videoTypeName = Enum.GetName(typeof(MediaFileType), MediaFileType.Video).ToLowerInvariant();

                if (type.ToLower().StartsWith(imageTypeName, StringComparison.CurrentCultureIgnoreCase))
                {
                    var fullImage  = ImageHelpers.RotateImage(path, 1);
                    var thumbImage = ImageHelpers.RotateImage(path, 0.25f);


                    fullPath = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, $"{fileName}{ext}");
                    File.WriteAllBytes(fullPath, fullImage);

                    thumbnailImagePath = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, $"{fileName}-THUMBNAIL{ext}");
                    File.WriteAllBytes(thumbnailImagePath, thumbImage);
                }
                else if (type.ToLowerInvariant().StartsWith(videoTypeName, StringComparison.CurrentCultureIgnoreCase))
                {
                    fullPath = path;
                    var bitmap = ThumbnailUtils.CreateVideoThumbnail(path, ThumbnailKind.MiniKind);

                    thumbnailImagePath = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, $"{fileName}-THUMBNAIL{ext}");
                    var stream = new FileStream(thumbnailImagePath, FileMode.Create);
                    bitmap?.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                    stream.Close();

                    mediaFileType = MediaFileType.Video;
                }

                if (!string.IsNullOrEmpty(fullPath) && !string.IsNullOrEmpty(thumbnailImagePath))
                {
                    mediaFile = new MediaFile()
                    {
                        Path        = fullPath,
                        Type        = mediaFileType,
                        PreviewPath = thumbnailImagePath
                    };
                }
            }

            return(mediaFile);
        }
        static async Task PlatformSaveAsync(MediaFileType type, string filePath)
        {
            using var fileUri = new NSUrl(filePath);

            await PhotoLibraryPerformChanges(() =>
            {
                using var request = type == MediaFileType.Video
                ? PHAssetChangeRequest.FromVideo(fileUri)
                : PHAssetChangeRequest.FromImage(fileUri);
            });
        }
Beispiel #19
0
 private void handleFileElementTap(string file, MediaFileType fileType)
 {
     if (fileType == MediaFileType.Movie)
     {
         onMovieFileSelected(file);
     }
     else if (fileType == MediaFileType.Image)
     {
         onImageFileSelected(file);
     }
 }
Beispiel #20
0
        public void SetHTMLDesignerInsertMediaData(MediaFileType type, InsertMediaData data)
        {
            XmlElement element = GetMediaElement(type);

            element.SetAttribute("vMargin", data.MediaVMargin.ToString());
            element.SetAttribute("scale", data.MediaScale.ToString());
            element.SetAttribute("quality", data.MediaQuality.ToString());
            element.SetAttribute("hMargin", data.MediaHMargin.ToString());
            element.SetAttribute("align", data.MediaAlign.ToString());

            this.Save();
        }
Beispiel #21
0
        /// <summary>Convert to MediaFile_Type for IMDI meta data file</summary>
        public MediaFileType ToMediaFileType(string sessionDirectoryName)
        {
            var mediaFile = new MediaFileType();

            SetResourceProperties(mediaFile, sessionDirectoryName);

            mediaFile.Quality = new QualityType {
                Type = VocabularyTypeValueType.ClosedVocabulary, Value = "Unspecified"
            };

            return(mediaFile);
        }
Beispiel #22
0
        static string SelectResource(MediaFileType type, Form ownerForm)
        {
            //SelectFileForm dlg = new SelectFileForm(type);
            //dlg.BringToFront();
            //if (dlg.ShowDialog(ownerForm) == DialogResult.OK)
            //{
            //    return dlg.FileId;
            //}
            ResourcesManagerForm dlg = new ResourcesManagerForm();

            dlg.BringToFront();
            dlg.ShowDialog(ownerForm);
            return(null);
        }
Beispiel #23
0
        public MediaFile(MediaFile mediaFile, string alias, string fileName, MediaFileType fileType)
        {
            this.isMutedAll   = mediaFile.isMutedAll;
            this.isMutedLeft  = mediaFile.isMutedLeft;
            this.isMutedRight = mediaFile.isMutedRight;
            this.allVolume    = mediaFile.allVolume;
            this.lftVolume    = mediaFile.lftVolume;
            this.rtVolume     = mediaFile.rtVolume;
            this.trebVolume   = mediaFile.trebVolume;
            this.bassVolume   = mediaFile.bassVolume;
            this.balance      = mediaFile.balance;
            this.isLooping    = mediaFile.isLooping;

            // if opening a media file directly, make a copy of it first, to allow multiple instances
            if (!IsTempFile)
            {
                _tmpFileName = SaveFileToTmpDir(fileName);
            }

            // if the alias already exists, remove the old MediaFile and replace it with this
            if (_mediaFiles.ContainsKey(alias))
            {
                _mediaFiles[alias].Dispose();
            }

            // add this new MediaFile to static list
            _mediaFiles.Add(alias, this);

            Alias    = alias;
            FileName = fileName;
            FileType = fileType;

            IsPlaying = false;
            IsPaused  = false;

            Open();

            // set variables again after Open() to issue MCI commands
            MuteAll      = isMutedAll;
            MuteLeft     = isMutedLeft;
            MuteRight    = isMutedRight;
            VolumeAll    = allVolume;
            VolumeLeft   = lftVolume;
            VolumeRight  = rtVolume;
            VolumeTreble = trebVolume;
            VolumeBass   = bassVolume;
            Balance      = balance;
            Looping      = isLooping;
        }
Beispiel #24
0
        /// <summary>Opens media files Picker</summary>
        /// <param name="selectionLimit">Maximum count of files to pick. On Android the option just sets multiple pick allowed.</param>
        /// <param name="types">Media file types available for picking</param>
        /// <returns>Media files selected by a user.</returns>
        public static async Task <MediaPickResult> PickAsync(int selectionLimit = 1, params MediaFileType[] types)
        {
            if (!(types?.Length > 0))
            {
                types = new MediaFileType[] { MediaFileType.Image, MediaFileType.Video }
            }
            ;

            if (selectionLimit < 0)
            {
                selectionLimit = 1;
            }

            return(new MediaPickResult(await PlatformPickAsync(selectionLimit, types)));
        }
        static async Task PlatformSaveAsync(MediaFileType type, byte[] data, string fileName)
        {
            string filePath = null;

            try
            {
                filePath = GetFilePath(fileName);
                await File.WriteAllBytesAsync(filePath, data);

                await PlatformSaveAsync(type, filePath);
            }
            finally
            {
                DeleteFile(filePath);
            }
        }
Beispiel #26
0
        public static string GetOutputPath(MediaFileType type, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                string timestamp = DateTime.Now.ToString("yyyMMdd_HHmmss");
                if (type == MediaFileType.Image)
                {
                    name = "IMG_" + timestamp + ".jpg";
                }
                else
                {
                    name = "VID_" + timestamp + ".mp4";
                }
            }

            return(GetFullPath(GetUniqueName(type, name)));
        }
        public async Task Play(string url, MediaFileType fileType)
        {
            try
            {
                var mediaPlaybackList = new MediaPlaybackList();
                var mediaSource       = await CreateMediaSource(url, fileType);

                var item = new MediaPlaybackItem(mediaSource);
                mediaPlaybackList.Items.Add(item);
                _player.Source = mediaPlaybackList;
                _player.Play();
            }
            catch (Exception e)
            {
                MediaFailed?.Invoke(this, new MediaFailedEventArgs("Unable to start playback", e));
            }
        }
        static async Task PlatformSaveAsync(MediaFileType type, Stream fileStream, string fileName)
        {
            string filePath = null;

            try
            {
                filePath         = GetFilePath(fileName);
                using var stream = File.Create(filePath);
                await fileStream.CopyToAsync(stream);

                stream.Close();

                await PlatformSaveAsync(type, filePath);
            }
            finally
            {
                DeleteFile(filePath);
            }
        }
Beispiel #29
0
        public static string GetOutputPath(MediaFileType type, string path, string name)
        {
            path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), path);
            Directory.CreateDirectory(path);

            if (string.IsNullOrWhiteSpace(name))
            {
                string timestamp = DateTime.Now.ToString("yyyMMdd_HHmmss");
                if (type == MediaFileType.Image)
                {
                    name = "IMG_" + timestamp + ".jpg";
                }
                else
                {
                    name = "VID_" + timestamp + ".mp4";
                }
            }
            return(Path.Combine(path, GetUniquePath(type, path, name)));
        }
Beispiel #30
0
        public InsertMediaData GetHTMLDesignerInsertMediaData(MediaFileType type)
        {
            XmlElement element = GetMediaElement(type);

            //如果没有属性,则表示是刚创建的元素
            if (!element.HasAttributes)
            {
                return(null);
            }

            InsertMediaData mediaData = new InsertMediaData();

            mediaData.MediaAlign   = int.Parse(element.GetAttribute("align"));
            mediaData.MediaHMargin = decimal.Parse(element.GetAttribute("hMargin"));
            mediaData.MediaQuality = int.Parse(element.GetAttribute("quality"));
            mediaData.MediaScale   = int.Parse(element.GetAttribute("scale"));
            mediaData.MediaVMargin = decimal.Parse(element.GetAttribute("vMargin"));
            return(mediaData);
        }
		RootElement[] GetMediaElements (string rootPath, MediaFileType fileType)
		{
			var elements = new List<RootElement> ();
			if (Directory.Exists (rootPath)) {
				foreach ( string directory in Directory.GetDirectories (rootPath)) {
					string shortDirName = Path.GetFileName (directory);
					var element = new RootElement (shortDirName);
					string text = fileType == MediaFileType.Movie ? "Touch file to play" : "Touch file to view";
					var fileSection = new Section (text);
					element.Add (fileSection);
					foreach (string file in Directory.GetFiles (directory)) {
						var fileElement = new FileElement (Path.GetFileName (file), fileType, handleFileElementTap);
						fileElement.Path = file;
						fileSection.Add (fileElement);
					}
					elements.Add (element);
				}
			}
			return elements.ToArray ();
		}
Beispiel #32
0
        public MediaFile(string alias, string fileName, MediaFileType fileType)
        {
            // if opening a media file directly, make a copy of it first, to allow multiple instances
            if (!IsTempFile)
                _tmpFileName = SaveFileToTmpDir(fileName);

            // if the alias already exists, remove the old MediaFile and replace it with this
            if (_mediaFiles.ContainsKey(alias))
                _mediaFiles[alias].Dispose();

            // add this new MediaFile to static list
            _mediaFiles.Add(alias, this);

            Alias = alias;
            FileName = fileName;
            FileType = fileType;

            IsPlaying = false;
            IsPaused = false;

            Open();
        }
		public FileElement( string caption, MediaFileType fileType, fileElementTapHandler handler ) : base(caption)
		{
			this.Tapped += delegate 
			{
				handler( this.Path, FileType );
			};
			this.FileType = fileType;
		}
 public async Task Play(string url, MediaFileType fileType)
 {
     _loadMediaTaskCompletionSource = new TaskCompletionSource<bool>();
     try
     {
         if (_currentMediaSource != null)
         {
             _currentMediaSource.StateChanged -= MediaSourceOnStateChanged;
             _currentMediaSource.OpenOperationCompleted -= MediaSourceOnOpenOperationCompleted;
         }
         // Todo: sync this with the playback queue
         var mediaPlaybackList = new MediaPlaybackList();
         _currentMediaSource = await CreateMediaSource(url, fileType);
         _currentMediaSource.StateChanged += MediaSourceOnStateChanged;
         _currentMediaSource.OpenOperationCompleted += MediaSourceOnOpenOperationCompleted;
         var item = new MediaPlaybackItem(_currentMediaSource);
         mediaPlaybackList.Items.Add(item);
         _player.Source = mediaPlaybackList;
         _player.Play();
     }
     catch (Exception)
     {
         Debug.WriteLine("Unable to open url: " + url);
     }
 }
 public async Task Play(string url, MediaFileType fileType)
 {
     await Play(new MediaFile(url, fileType));
 }
		/// <summary>
		/// Creates a new <see cref="MediaFileNodeType"/>
		/// </summary>
		/// <param name="mediaFileType">The type of <see cref="IMediaFile"/> to return</param>
		public MediaFileNodeType(MediaFileType mediaFileType)
			: this(mediaFileType, false)
		{		
		}
Beispiel #37
0
 public MediaFile(string alias, EngineResourceFileIdentifier resId, MediaFileType fileType)
     : this(alias, SaveStreamToTmpDir(resId.Data), fileType)
 {
     IsTempFile = true;
     InputStream = resId.Data;
 }
Beispiel #38
0
 public MediaFile(string alias, Stream fileData, MediaFileType fileType)
     : this(alias, SaveStreamToTmpDir(fileData), fileType)
 {
     IsTempFile = true;
     InputStream = fileData;
 }
Beispiel #39
0
        private string OpenFileType(MediaFileType fileType, out EngineResourceFileTypes resFileType)
        {
            switch (fileType)
            {
                case MediaFileType.wav:
                    resFileType = EngineResourceFileTypes.Audio;
                    return "waveaudio";

                case MediaFileType.mid:
                case MediaFileType.midi:
                    resFileType = EngineResourceFileTypes.Audio;
                    return "sequencer";

                case MediaFileType.wma:         // audio
                case MediaFileType.mp3:         // audio
                    resFileType = EngineResourceFileTypes.Audio;
                    return "mpegvideo";

                case MediaFileType.avi:         // video
                case MediaFileType.ogg:         // video
                case MediaFileType.mpg:         // video
                case MediaFileType.mpeg:        // video
                case MediaFileType.wmv:         // video
                case MediaFileType.asx:         // video
                case MediaFileType.unknown:     // assume video
                default:
                    resFileType = EngineResourceFileTypes.Video;
                    return "mpegvideo";
            }
        }
Beispiel #40
0
        public MediaFile(MediaFile mediaFile, string alias, string fileName, MediaFileType fileType)
        {
            this.isMutedAll = mediaFile.isMutedAll;
            this.isMutedLeft = mediaFile.isMutedLeft;
            this.isMutedRight = mediaFile.isMutedRight;
            this.allVolume = mediaFile.allVolume;
            this.lftVolume = mediaFile.lftVolume;
            this.rtVolume = mediaFile.rtVolume;
            this.trebVolume = mediaFile.trebVolume;
            this.bassVolume = mediaFile.bassVolume;
            this.balance = mediaFile.balance;
            this.isLooping = mediaFile.isLooping;

            // if opening a media file directly, make a copy of it first, to allow multiple instances
            if (!IsTempFile)
                _tmpFileName = SaveFileToTmpDir(fileName);

            // if the alias already exists, remove the old MediaFile and replace it with this
            if (_mediaFiles.ContainsKey(alias))
                _mediaFiles[alias].Dispose();

            // add this new MediaFile to static list
            _mediaFiles.Add(alias, this);

            Alias = alias;
            FileName = fileName;
            FileType = fileType;

            IsPlaying = false;
            IsPaused = false;

            Open();

            // set variables again after Open() to issue MCI commands
            MuteAll = isMutedAll;
            MuteLeft = isMutedLeft;
            MuteRight = isMutedRight;
            VolumeAll = allVolume;
            VolumeLeft = lftVolume;
            VolumeRight = rtVolume;
            VolumeTreble = trebVolume;
            VolumeBass = bassVolume;
            Balance = balance;
            Looping = isLooping;
        }
		/// <summary>
		/// Creates a new <see cref="MediaFileNodeType"/>
		/// </summary>
		/// <param name="uniqueInstance">True if the <see cref="IMediaFile"/> returned should be a new unique instance (uncached)</param>
		public MediaFileNodeType(MediaFileType mediaFileType, bool uniqueInstance)
			: base(mediaFileType.RuntimeType)
		{			
			this.MediaFileType = mediaFileType;
			this.UniqueInstance = uniqueInstance;
		}
		private void handleFileElementTap( string file, MediaFileType fileType )
		{
			if ( fileType == MediaFileType.Movie )
			{
				onMovieFileSelected( file );		
			}
			else if ( fileType == MediaFileType.Image )
			{
				onImageFileSelected( file );		
			}
		}
 public MediaFile(string url, MediaFileType type)
 {
     Url = url;
     Type = type;
 }
 public async Task Play(string url, MediaFileType fileType)
 {
     try
     {
         var mediaPlaybackList = new MediaPlaybackList();
         var mediaSource = await CreateMediaSource(url, fileType);
         var item = new MediaPlaybackItem(mediaSource);
         mediaPlaybackList.Items.Add(item);
         _player.Source = mediaPlaybackList;
         _player.Play();
     }
     catch (Exception e)
     {
         MediaFailed?.Invoke(this, new MediaFailedEventArgs("Unable to start playback", e));
     }
 }
 private void SetCurrentPlayer(MediaFileType fileType)
 {
     if (_currentPlaybackManager != null)
     {
         RemoveEventHandlers();
     }
     switch (fileType)
     {
         case MediaFileType.AudioUrl:
         case MediaFileType.AudioFile:
             _currentPlaybackManager = AudioPlayer;
             break;
         case MediaFileType.VideoUrl:
         case MediaFileType.VideoFile:
             _currentPlaybackManager = VideoPlayer;
             break;
         case MediaFileType.Other:
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     AddEventHandlers();
 }
        public async Task Play(string filePath, MediaFileType mediaFileType, string title = null)
        {
            try
            {
                _filePath = filePath;
                if (_playbackStateSubject.Latest().First() == MediaPlayerStatus.Paused)
                {
                    await Pause();
                    return;
                }

                _canPlaySubject.OnNext(true);
                await CrossMediaManager.Current.Play(filePath, mediaFileType);
                _titleSubject.OnNext(title);
            }
            catch (Exception e)
            {
                _canPlaySubject.OnNext(false);
                Debug.WriteLine(e);
            }
        }
 private async Task<MediaSource> CreateMediaSource(string url, MediaFileType fileType)
 {
     switch (fileType)
     {
         case MediaFileType.AudioUrl:
         case MediaFileType.VideoUrl:
             return MediaSource.CreateFromUri(new Uri(url));
         case MediaFileType.AudioFile:
         case MediaFileType.VideoFile:
             var du = _player.SystemMediaTransportControls.DisplayUpdater;
             var storageFile = await StorageFile.GetFileFromPathAsync(url);
             var playbackType = fileType == MediaFileType.AudioFile
                 ? MediaPlaybackType.Music
                 : MediaPlaybackType.Video;
             await du.CopyFromFileAsync(playbackType, storageFile);
             du.Update();
             return MediaSource.CreateFromStorageFile(storageFile);
         case MediaFileType.Other:
             break;
         default:
             throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);
     }
     return MediaSource.CreateFromUri(new Uri(url));
 }
 public MediaFile(string url, MediaFileType type)
 {
     Url = url;
     Type = type;
     Metadata = new MediaFileMetadata();
 }