Ejemplo n.º 1
0
        private async void SoundGridView_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var items = await e.DataView.GetStorageItemsAsync();

                if (items.Any())
                {
                    var storageFile = items[0] as StorageFile;
                    var contentType = storageFile.ContentType;

                    StorageFolder folder = ApplicationData.Current.LocalFolder;

                    if (contentType == "audio/wav" || contentType == "audio/mpeg")
                    {
                        StorageFile newFile = await storageFile.CopyAsync(folder,
                                                                          storageFile.Name, NameCollisionOption.GenerateUniqueName);

                        MyMediaElement.SetSource(await storageFile.OpenAsync(FileAccessMode.Read),
                                                 contentType);
                        MyMediaElement.Play();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private async void SoundGridView_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))          // Makes sure what being dragged and dropped is a file.
                                                                                // StorageItems - not fragments of text or something from an app.
            {
                var items = await e.DataView.GetStorageItemsAsync();            // Get a reference to all those items. Only working with 1 item.

                if (items.Any())                                                // Make sure there are items in the drag operation
                {
                    var storageFile = items[0] as StorageFile;                  // Get first item at index 0
                    var contentType = storageFile.ContentType;                  // Get the content type - image/sound/documet

                    StorageFolder folder = ApplicationData.Current.LocalFolder; // Reference to the local folder (storage).

                    if (contentType == "audio/wav" || contentType == "audio/mpeg")
                    {
                        // Save in a folder, filename, if there's a same name, generate a unique name.
                        StorageFile newFile = await storageFile.CopyAsync(folder, storageFile.Name, NameCollisionOption.GenerateUniqueName);

                        MyMediaElement.SetSource(await storageFile.OpenAsync(FileAccessMode.Read), contentType);
                        MyMediaElement.Play();  // Play the dragged song
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private async void SoundGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            Song songInContext = (Song)e.ClickedItem;

            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFile   file        = await localFolder.GetFileAsync(songInContext.SongFileName);

            if (file != null)
            {
                //_mediaSource = MediaSource.CreateFromStorageFile(file);
                //this.mediaPlayer.SetPlaybackSource(_mediaSource);
                //this.mediaPlayer.AutoPlay = true;
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

                MyMediaElement.SetSource(stream, file.ContentType);
                //MyMediaElement.PosterSource = songInContext.CoverImage;
            }
            if (playing)
            {
                MyMediaElement.AutoPlay = false;
                playing = false;
            }
            else
            {
                playing = true;
                MyMediaElement.AutoPlay  = true;
                MediaElementImage.Source = songInContext.CoverImage;
            }
        }
Ejemplo n.º 4
0
        private async void SoundGridView_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var items = await e.DataView.GetStorageItemsAsync();

                if (items.Any())
                {
                    var storageFile = items[0] as StorageFile;
                    var contentType = storageFile.ContentType;

                    var localFolder = ApplicationData.Current.LocalFolder;

                    if (contentType == "image/png" || contentType == "image/jpeg")
                    {
                        var newFile = await storageFile.CopyAsync(localFolder, storageFile.Name, NameCollisionOption.GenerateUniqueName);

                        if (_soundToAdd == null)
                        {
                            _soundToAdd = new Sound
                            {
                                Name      = storageFile.Name,
                                ImageFile = newFile.Path,
                                Category  = SoundCategory.Custom
                            };
                        }
                        else
                        {
                            _soundToAdd.ImageFile = newFile.Path;
                        }
                    }
                    else if (contentType == "audio/wav" || contentType == "audio/mpeg")
                    {
                        var newFile = await storageFile.CopyAsync(localFolder, storageFile.Name, NameCollisionOption.GenerateUniqueName);

                        if (_soundToAdd == null)
                        {
                            _soundToAdd = new Sound
                            {
                                Name      = string.Empty,
                                AudioFile = newFile.Path,
                                ImageFile = string.Empty,
                                Category  = SoundCategory.Custom
                            };
                        }
                        else
                        {
                            _soundToAdd.AudioFile = newFile.Path;
                        }

                        MyMediaElement.SetSource(await storageFile.OpenAsync(FileAccessMode.Read), contentType);
                        MyMediaElement.Play();
                    }
                    AddSoundIfComplete();
                }
            }
        }
 private async void CountDown_Completed(object sender, object e)
 {
     if (!_playingMusic)
     {
         var song = PickSong();
         MyMediaElement.SetSource(await song.SongFile.OpenAsync(FileAccessMode.Read), song.SongFile.ContentType);
         StartCountdown();
     }
 }
 private async void SkipCooldown_ClickAsync(object sender, RoutedEventArgs e)
 {
     if (!_playingMusic)
     {
         var song = PickSong();
         MyMediaElement.SetSource(await song.SongFile.OpenAsync(FileAccessMode.Read), song.SongFile.ContentType);
         StartCountdown();
     }
 }
        private async void VideoImageGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            MyMediaElement.Visibility = Visibility.Visible;
            Images        videoInContext = (Images)e.ClickedItem;
            StorageFolder localFolder    = ApplicationData.Current.LocalFolder;
            StorageFile   file           = await localFolder.GetFileAsync(videoInContext.videoFileName);

            if (file != null)
            {
                IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

                MyMediaElement.SetSource(fileStream, file.ContentType);
            }
            MyMediaElement.AutoPlay = true;
        }
Ejemplo n.º 8
0
        private async void CountdownFinished(object sender, object e)
        {
            if (!playmusic)
            {
                // Music Starts Playing
                var song = ChooseSong();

                MyMediaElement.SetSource(
                    await song.SongFile.OpenAsync(FileAccessMode.Read),
                    song.SongFile.ContentType);

                // Start countdown
                CountdownStr();
            }
        }
        private async void VideoImageGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var count = e.AddedItems.Count;

            if (count > 0)
            {
                Images        videoInContext = (Images)e.AddedItems.ElementAt(count - 1);
                StorageFolder localFolder    = ApplicationData.Current.LocalFolder;
                StorageFile   file           = await localFolder.GetFileAsync(videoInContext.videoFileName);

                if (file != null)
                {
                    IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

                    MyMediaElement.SetSource(fileStream, file.ContentType);
                }
                MyMediaElement.AutoPlay = true;
            }
        }
        private async void CountDown_CompletedAsync(object sender, object e)
        {
            if (!_playingMusic)
            {
                var song = PickSong();

                MyMediaElement.SetSource
                    (await song.SongFile.OpenAsync(FileAccessMode.Read),
                    song.SongFile.ContentType);


                StartCountdown();
            }
            else
            {
                InstructionTextBlock.Text       = "Time's up, Lets just see if you could get it right";
                InstructionTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                //StartCooldown();
            }
        }
Ejemplo n.º 11
0
        private void PrePlayThread(object param)
        {
            var    song = param as SongEx;
            string ext  = song.FilePath.Substring(song.FilePath.LastIndexOf(".") + 1);

            if (InteropSvc.InteropLib.Instance.GetFileAttributes7("\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong." + ext) != 0xFFFFFFFF)
            {
                InteropSvc.InteropLib.Instance.MoveFile7("\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong." + ext,
                                                         "\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong2." + ext);
                InteropSvc.InteropLib.Instance.DeleteFile7("\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong2." + ext);
            }
            bool res = InteropSvc.InteropLib.Instance.CopyFile7(song.FilePath, "\\Applications\\Data\\9cefc0bf-7060-45b0-ba66-2d1dcad8dc3c\\Data\\IsolatedStore\\PlayingSong." + ext, false);

            Dispatcher.BeginInvoke(delegate()
            {
                int retries = 0;
                L_tryAgain:
                try
                {
                    using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
                        using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream("PlayingSong." + ext, FileMode.Open, FileAccess.Read, FileShare.Read, isolatedStorageFile))
                        {
                            MyMediaElement.SetSource(isolatedStorageFileStream);
                        }
                }
                catch (Exception ex)
                {
                    if (retries < 5)
                    {
                        retries++;
                        Thread.Sleep(1000);
                        goto L_tryAgain;
                    }
                    if (BasicStates.CurrentState.Name != "CutRingtonePage_Normal")
                    {
                        VisualStateManager.GoToState(this, "CutRingtonePage_Normal", true);
                    }
                }
            });
        }
Ejemplo n.º 12
0
        private async void listViewArtists_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (playing)
            {
                var count = e.AddedItems.Count;
                if (count > 0)
                {
                    Song songInContext = (Song)e.AddedItems.ElementAt(count - 1);

                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    StorageFile   file        = await localFolder.GetFileAsync(songInContext.SongFileName);

                    if (file != null)
                    {
                        IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

                        MyMediaElement.SetSource(stream, file.ContentType);
                    }
                    MyMediaElement.AutoPlay  = true;
                    MediaElementImage.Source = songInContext.CoverImage;
                }
            }
        }
Ejemplo n.º 13
0
        private async void CountDown_Completed(object sender, object e)
        {
            if (!_playingMusic)
            {
                // Start playing music
                var song = PickSong();

                // Play the music
                MyMediaElement.SetSource(
                    await song.SongFile.OpenAsync(FileAccessMode.Read),
                    song.SongFile.ContentType);

                // Start countdown
                StartCountdown();
            }
            else
            {
                MyMediaElement.Stop();
                Song correctSong = Songs.FirstOrDefault(p => p.Selected);
                correctSong.Selected = false;
                correctSong.Used     = true;
                DisplayCorrectSong(correctSong);
                int addScore = (-1) * (int)MyProgressBar.Value;
                _totalScore += addScore;
                _round++;
                ResultTextBlock.Text = String.Format("Score: {0}, Total Score after {1} Rounds: {2}", addScore, _round, _totalScore);
                if (_round >= 5)
                {
                    InstructionTextBlock.Text  = String.Format("Game Over... You scored: {0}", _totalScore);
                    PlayAgainButton.Visibility = Visibility.Visible;
                }
                else
                {
                    StartCooldown();
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Performs all necessary actions (including SystemMediaTransportControls related) of loading a new media item
        /// in the app for playback.
        /// </summary>
        /// <param name="newItemIndex">index in playlist of new item to load for playback, can be out of range.</param>
        /// <remarks>
        /// If the newItemIndex argument is out of range, it will be adjusted accordingly to stay in range.
        /// </remarks>
        private async Task SetNewMediaItem(int newItemIndex)
        {
            // enable Next button unless we're on last item of the playlist
            if (newItemIndex >= playlist.Count - 1)
            {
                systemMediaControls.IsNextEnabled = false;
                newItemIndex = playlist.Count - 1;
            }
            else
            {
                systemMediaControls.IsNextEnabled = true;
            }

            // enable Previous button unless we're on first item of the playlist
            if (newItemIndex <= 0)
            {
                systemMediaControls.IsPreviousEnabled = false;
                newItemIndex = 0;
            }
            else
            {
                systemMediaControls.IsPreviousEnabled = true;
            }

            // note that the Play, Pause and Stop buttons were already enabled via SetupSystemMediaTransportControls()
            // invoked during this scenario page's OnNavigateToHandler()


            currentItemIndex = newItemIndex;
            StorageFile         mediaFile = playlist[newItemIndex];
            IRandomAccessStream stream    = null;

            try
            {
                stream = await mediaFile.OpenAsync(FileAccessMode.Read);
            }
            catch (Exception e)
            {
                // User may have navigated away from this scenario page to another scenario page
                // before the async operation completed.
                if (isThisPageActive)
                {
                    // If the file can't be opened, for this sample we will behave similar to the case of
                    // setting a corrupted/invalid media file stream on the MediaElement (which triggers a
                    // MediaFailed event).  We abort any ongoing playback by nulling the MediaElement's
                    // source.  The user must press Next or Previous to move to a different media item,
                    // or use the file picker to load a new set of files to play.
                    MyMediaElement.Source = null;

                    string errorMessage = String.Format(@"Cannot open {0} [""{1}""]." +
                                                        "\nPress Next or Previous to continue, or select new files to play.",
                                                        mediaFile.Name,
                                                        e.Message.Trim());
                    //rootPage.NotifyUser(errorMessage, NotifyType.ErrorMessage);
                }
            }

            // User may have navigated away from this scenario page to another scenario page
            // before the async operation completed. Check to make sure page is still active.
            if (!isThisPageActive)
            {
                return;
            }

            if (stream != null)
            {
                // We're about to change the MediaElement's source media, so put ourselves into a
                // "changing media" state.  We stay in that state until the new media is playing,
                // loaded (if user has currently paused or stopped playback), or failed to load.
                // At those points we will call OnChangingMediaEnded().
                MyMediaElement.SetSource(stream, mediaFile.ContentType);
            }

            try
            {
                // Updates the system UI for media transport controls to display metadata information
                // reflecting the file we are playing (eg. track title, album art/video thumbnail, etc.)
                // We call this even if the mediaFile can't be opened; in that case the method can still
                // update the system UI to remove any metadata information previously displayed.
                await UpdateSystemMediaControlsDisplayAsync(mediaFile);
            }
            catch (Exception e)
            {
                // Check isThisPageActive as user may have navigated away from this scenario page to
                // another scenario page before the async operations completed.
                if (isThisPageActive)
                {
                    //rootPage.NotifyUser(e.Message, NotifyType.ErrorMessage);
                }
            }
        }