How to get the MediaPlayer Queue - c#

In my application I am using the MediaPlayer to play a selection of songs, however it would be good to be able to get the songs that are going to be played next and display them to the user, either for information, or so they can jump several songs in the queue.
So how can I get a list of the Songs that are coming up in the MediaPlayer queue?
So that I can have a list of them which can be displayed to the user, in some sort of container, probably a ListBox.
I have tried using MediaPlayerQueue however this operator doesn't seem to have any form of functionality?
Thank you for your time and help.

media player in windows phone 7 displaying next song
MediaPlayer.Queue[n]
will give you the required Song instance

You can try this one. It work for wp8.1 silverlight.
SongModel is my custom class
App.Handler.MediaPlayerQueqeLists = new ObservableCollection<SongModel>();
for (int i = 0; i < MediaPlayer.Queue.Count; i++)
{
App.Handler.MediaPlayerQueqeLists.Add(new SongModel
{
Index = i,
Title = MediaPlayer.Queue[i].Name,
Artist = MediaPlayer.Queue[i].Artist.Name,
StringDuration = (new DateTime(MediaPlayer.Queue[i].Duration.Ticks)).ToString("mm:ss")
});
}
llsPlaylist.ItemsSource = App.Handler.MediaPlayerQueqeLists;

Related

Populating a listbox in a seperate window gives me a InvalidOperationException. I'm using WPF and .NET 6.0

As I was trying to learn how to use multiple windows in WPF, I stumbled upon a problem. I have a MainWindow containing all the logic for a blackjack game. Now I wanted a second Window with the last 10 games played by the user.
These last 10 games were stored in
public static ListBoxItem[] historiekArray = new ListBoxItem[10];
In the 'Speler' class (Player in Dutch). Now when I try to populate the HistoryWindow Listbox, everything goes well the first time, but the second time I open up the window this error occurs:
System.InvalidOperationException: 'Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.'
This is the C# code in the HistoryWindow.xaml.cs
public HistoriekWindow()
{
InitializeComponent();
// empty the listbox
LbxHistoriek.Items.Clear();
// Populate listbox with array items
for (int i = 0; i < Speler.historiekArray.Length - 1; i++)
{
ListBoxItem temp = new ListBoxItem();
temp = Speler.historiekArray[i];
LbxHistoriek.Items.Add(temp);
}
}
Looking at other posts on StackOverflow and learn.microsoft, I thought the problem might be that my ListBoxItem was being reused, but after placing ListboxItem temp = new ListboxItem() inside the for-loop, nothing much changed.
SOLUTION
The array of ListboxItems was changed into an Array of strings.
public static string[] historiekArray = new string[10];
And the for-loop sets the .Content of the ListBoxItem to the corresponding Array item.
for (int i = 0; i < Speler.historiekArray.Length - 1; i++)
{
ListBoxItem temp = new ListBoxItem();
temp.Content = Speler.historiekArray[i];
LbxHistoriek.Items.Add(temp);
}
Please excuse my formatting, this is my first post on StackOverflow and English is not my native language.

Populating winform ListView from Calling External Class, not adding image and text

I am trying to add a new image list with text describing each image below each image. I have set the listview to large icons and tried many other attempts to get preview images back into the first form.
I have been able to either
1. get very small images into the list view
2. get just the text into the listview
3. get the very tiny images again with text first then the images, not together.
I have tried all the overloaded methods and I am still at a loss as to why i can't even get a Properties.resources.image in as an image placeholder. except as a tiny image. And yes I have set the listview large icon mode and tried the imageSize properties, nothing works. Also some attempts usually with a technique that appears like it is following an explanation on here fails to show anything in the listview on the frstForm.
Any hints would be appreciated.
public ImageList imageList_c = new ImageList();
private Family_Loader_ExtEventDialog _frstForm;
foreach (KeyValuePair<string, Bitmap> kvp in element_Dict(_doc_new, BuiltInCategory.OST_Walls))
{
//imageList_c.ImageSize = new Size(120, 120);
//imageList_c.Images.Add(kvp.Key, Properties.Resources.folder);
_frstForm.listView_Family.Items.Add(kvp.Key);
}
//_frstForm.listView_Family.LargeImageList = imageList_c;
imageList_c.Images.Add(kvp.Key, kvp.Value);
_frstForm.listView_Family.View = System.Windows.Forms.View.LargeIcon;
_frstForm.listView_Family.LargeImageList = imageList_c;
for (int i = 0; i < imageList_c.Images.Count; i++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = i;
item.Text = imageList_c.Images.Keys[i];
_frstForm.listView_Family.Items.Add(item);
}

How to animate live tiles using notification extensions?

I want to animate lives tiles in UAP applications. But I am getting this exception:
Cannot implicitly convert type 'NotificationsExtensions.Tiles.TileImageSource' to 'string'.
I am using this code:
TileBindingContentAdaptive largebindingContent = new TileBindingContentAdaptive()
{
PeekImage = new TilePeekImage()
{
Source = new TileImageSource("Assets/Apps/Hipstame/hipster.jpg")
},
Children =
{
new TileText() {Text =Description, Wrap = true, Style = TileTextStyle.BodySubtle}
}
};
How can I animate my live tiles?
Cannot implicitly convert type 'NotificationsExtensions.Tiles.TileImageSource' to 'string'.
The reason you are getting this exception is because as of May 2016 NotificationsExtensions received some updates where there have been changes made to TileBackgroundImage and TilePeekImage. You can see the details of these changes here in the msdn update post.
Specifically, the property type for Source changed from TileImageSource to string. This change means that you need to change the way you are setting Source. Note in the code below (yours, which I modified) where the Source is simply a string. This should resolve the exception you are getting.
TileBindingContentAdaptive largebindingContent = new TileBindingContentAdaptive()
{
PeekImage = new TilePeekImage()
{
Source = "Assets/Apps/Hipstame/hipster.jpg"
},
Children =
{
new TileText()
{
Text = Description,
Wrap = true,
Style = TileTextStyle.BodySubtle
}
}
};
As far as animating your live tiles there are a variety of things you can do and I cannot give any specific advice unless you specify what you want to do with your tiles. For example, if you want to cycle through images in your live tile you can take a look at this example here for cycling multiple images with an animation through a live tile. You can also refer to the msdn Adaptive Tile Templates documentation if you want to read through in more detail about what else you can do with your tiles.

Mp3 player in c#. Problems with the playlist

I´m currently working in a mp3 player and I want to make a playlist using a Listbox, this is what I have:
private void addSongToPlaylist_Click(object sender, EventArgs e)
{
OpenFileDialog dialog2 = new OpenFileDialog(); //Dialog to choose songs
dialog2.Multiselect = true; // To choose multiple songs in the same dialog
if (dialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
files= dialog2.SafeFileNames;
paths = dialog2.FileNames;
for (int i = 0; i < files.Length; i++) // Add song to the playlist
{
listBox1.Items.Add(files[i]);
}
}
When I run the code it works properly if I select one or multiple songs in one single dialog.
The problem is that every time I press the "Add Song to playlist" button (to add multiple songs separately), the counter variable is reset to zero and therefore I´m not able to add more than one song separately.
I´ve tried declaring a global int variable named "songCount"
int songCount = 0;
To use it like this:
for (int i = 0; i < files.Length; i++) // Add song to the playlist
{
listBox1.Items.Add(files[songCount]);
}
songCount++;
When I run the code and I add a second song to the playlist, I get a 'System.IndexOutOfRangeException', I don´t know how to solve the problem. Please help.

Combobox filled with FontFamilies set SelectedItem

i have a problem:
I want to make little Note Application for personal use. In this little Scratchpad i have a settings menu with a combobox for all the installed Fonts.
FontFamilyDrop.ItemsSource = Fonts.SystemFontFamilies;
Now i want to save and read this value in my settings.ini file.
Writing the value works perfectly by converting the SelectedItem to a string.
When the user opens the settings menu, i want to preload the current font and i dont know how to set the SelectedItem property by just having a string for lets say "Lucida Console".
I've tried this one now:
for (int i = 2; i <= FontFamilyArray.GetLength(0); i++)
{
Title = FontFamilyArray[i].ToString();
}
The problem is that it doesnt work. It throws an exception.
Now the thing that makes me confused is, that when i fill in "2" instead of i like this:
for (int i = 2; i <= FontFamilyArray.GetLength(0); i++)
{
Title = FontFamilyArray[2].ToString();
}
This way it works perfectly... Does anyone know why?

Categories