Setting AlbumArt of AudioTrack - c#

I'm using Background Audio Player on Windows Phone 8 and I'm trying to set an album art for my audio track. As I've read here and at MSDN the image MUST be at shared/media/ - ok I've checked the image is there and I try to do:
AudioTrack myTrack = new AudioTrack(track.source, track.Title, track.Artist, track.Album, new Uri("shared/media/Episode29.jpg", UriKind.Relative));
The music starts, but there is no image. Am I doing something wrong?
I've also run Background Audio Player Sample mentioned here at MSDN and I also see no image.

Related

How to play songs in repeat mode in an UWP app

I have created a UWP app to play certain tracks in the background. Basically by following this link: https://blogs.windows.com/buildingapps/2016/01/13/the-basics-of-background-audio/ .
I want to set the repeat count for certain songs, so if a song has repeat count 10, that song is meant to be repeated 10 times before moving on to the next song in the playlist.
On the Windows phone 8.0 platform, the AudioPlayerAgent had the following event which indicated that the play state has changed. It was easy to override that event and add custom logic to repeat songs.
protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
{
switch (playState)
{
case PlayState.TrackEnded:
// keep repeating the same track
player.Position = new TimeSpan(0, 0, (int)0);
// add custom logic here..
break;
}
NotifyComplete();
}
What would be an equivalent event in the UWP platform?
So far I have tried the following events on the UWP platform, but to no avail..
BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;
BackgroundMediaPlayer.Current.MediaEnded += Current_MediaEnded;
BackgroundMediaPlayer.Current.MediaOpened += Current_MediaOpened;
With Windows 10, version 1607, a new single-process model has been introduced that greatly simplifies the process of enabling background audio.
Media continues to play when your app moves from the foreground to the background. This means that even after the user has minimized your app, returned to the home screen, or has navigated away from your app in some other way, your app can continue to play audio.
Starting with Windows 10, version 1607,the recommended best practice for playing media is to use the MediaPlayer class instead of MediaElement
Play a media file with MediaPlayer
_mediaPlayer = new MediaPlayer();
_mediaPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/example_video.mkv"));
_mediaPlayer.Play();
MSDN: Play media in the background
Now your app can manage the playlist or loop settings and use the media player instance to call Play method again.

Windows Library to play a video file

this.Background = new System.Windows.Media.ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri(label)));
The above code used the Media library to display an image from the Uri fed.(label contains the URL).
What library should I use to play a video file in the same manner.
(I need to play a video file instead of displaying and image)
Help ?
You can use the MediaElement for this.
It is located in System.Windows.Controls namespace and relies on the Windows Media Player. IF WMP is installed on your system MediaElement is an easy way to go.
The code to do this should look like this:
MediaElement me = new MediaElement();
// initialize and do other stuff to MediaElement
this.Background = new VisualBrush(me);

how I put sound in a silverlight animation?

I'm trying to put a sound to play when the animation in my silverlight animation starts. I put the sound in the user control with blend, selected auto-play, and created a PlaySoundAction to play the sound on load. Nothing worked. Anyone knows what I could be missing?
Did you use Media Element? since you have not posted any code, here is a sample on how to include sound in silverlight
MediaElement media = new MediaElement();
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("YourNameSpace.Sound1.wav");
media.SetSource(stream);
media.AutoPlay = false;
media.Stop();
media.Play();

Need to select a frame in gif

I need to restart a gif image so it will start from the first frame.
I have little experience with gif images in C#. I work on a C# windows form application. My gif image is in a picturebox. I need to restart it each time a person for example presses a button.
I have tried doing:
pictureBox1.Image.SelectActiveFrame(new FrameDimension(pictureBox1.Image.FrameDimensionsList[0]), 0)
but it didnt show any change.
I also tried Image animator also no luck. I really need help it is for my final project in high school engineering.
I found that Image.SelectActiveFrame() doesn't seem to work because how it works is not what you thought. It just set the initial frame if there is some control reading its frame, the first frame read is the active frame. So after SelectActiveFrame() you have to re-assign the Image property of your pictureBox to that new Image, like this:
private void RestartToFrameIndex(int index){
pictureBox.Image.SelectActiveFrame(new FrameDimension(pictureBox.Image.FrameDimensionsList[0]), index);
pictureBox.Image = pictureBox.Image;
}
//If you want to restart to the first frame, just call the method above like this:
RestartToFrameIndex(0);
That's the general solution I've just found :) hope it helps others...
I tried this solution and It's working fine :
Image animated = pictureBox1.Image;
pictureBox1.Image = animated;
this way , you reset pictureBox1.Image so the animated GIF starts from beginning.

Display Current Video in Windows Phone 8 using AudioVideoCaptureDevice?

I've managed to setup code for a Windows Phone 8 Application that initializes and can start/stop recording video using an AudioVideoCaptureDevice. (saves it to an IRandomAccessStream)
//Initialize Camera Recording
Windows.Foundation.Size resolution = new Windows.Foundation.Size(640, 480);
captureDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);
captureDevice.VideoEncodingFormat = CameraCaptureVideoFormat.H264;
captureDevice.AudioEncodingFormat = CameraCaptureAudioFormat.Aac;
captureDevice.RecordingFailed += captureDevice_RecordingFailed;
However, I cannot figure out how to hook this recording up to a VideoBrush to display the recording to the user. I want the user to be able to see the video they are recording as it is happening...
I know there is a tutorial that shows how to do this using the old APIs for Windows Phone 7 (CaptureSource, VideoDevice, etc.) but I specifically need to use the AudioVideoCaptureDevice to record. Anyone know how to display this video on screen?
Well, I was able to solve my problem.
Apparently there is a library in Microsoft.Devices that contains extensions for the VideoBrush class.
Therefore, in order to set the videobrush source to an AudioVideoCaptureDevice, you must first have:
using Microsoft.Devices;
at the top of your class in which your using the videobrush.
Hope this is able to help someone else.
You should be able to simply use VideoBrush.SetSource(captureDevice).

Categories

Resources