none
c# Windows Forms axWindowsMediaPlayer not updating media attributes RRS feed

  • Question

  • This is under Windows 10. I have a WinForms app with an embedded axWindowsMediaPlayer control. If a media entry has been previously added to the music library then it continues displaying the metadata it had when originally added no matter what. So, if the file was changed outside my app then those changes are not updated. It just keeps showing the out dated info. How can I get it to reflect any changes to the media?
     
    Here's my code. Besides the axWindowsMediaPlayer (mediaPlayer) I have a textbox (txtDetails) to display the title and duration and a listview (qList) containing the names of the current playlist items.

    private void AppendToList(string fileName)
            {
                try
                {
                    IWMPMedia mediaItem = mediaPlayer.mediaCollection.add(fileName);
                    mediaPlayer.currentPlaylist.appendItem(mediaItem);
                    qList.Items.Add(mediaItem.name);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Could Not Add " + fileName + " To Playlist", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

    private void PlaySelectedItem()
            {
                if (qList.SelectedItems.Count > 0)
                {
                    int selectedIndex = qList.SelectedIndices[0];
                    IWMPMedia selectedMedia = mediaPlayer.currentPlaylist.get_Item(selectedIndex);
                    mediaPlayer.Ctlcontrols.playItem(selectedMedia);
                                }
            }

            private void ViewItemDetails()
            {
                if (mediaPlayer.currentMedia != null)
                {
                    IWMPMedia media = mediaPlayer.currentMedia;

                    string title = media.getItemInfo("Title");               
                    string length = media.durationString;               
                   
                    txtDetails.Text = title + " " + length;
                                }
            }

    private void MediaPlayer_OpenStateChange(object sender, AxWMPLib._WMPOCXEvents_OpenStateChangeEvent e)
            {           
                if (e.newState == (int)WMPOpenState.wmposMediaOpen)
                {                               
                    ViewItemDetails();
                }
            }


    Wednesday, June 12, 2019 9:21 PM

All replies

  • Hi Clark,

    >> if the file was changed outside my app then those changes are not reflected

    Can you elaborate on your specific operation? What is the operation of "changed outside my app"?

    It would be better if you could provide a demo, a gif or video.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 13, 2019 2:05 AM
    Moderator
  • Hi Kyle,

    What I mean is that let's say I have an MP3 file that is 5:25 in length and it gets added to the music library. Then I make some edits to the file with another program and shorten it to 5:21. I then save it and replace the original MP3 that was 5:25. Now I run my app with code listed above, but when I display the durationString it still displays 5:25 for the mediaDuration even though it should be 5:21.

    Thursday, June 13, 2019 6:23 PM
  • Hi,

    Sorry, I have tried to reproduce the issue, but it failed. So, could you please provide a full project that can reproduce the issue? Just via "OneDrive" .

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 14, 2019 5:29 AM
    Moderator
  • Hi Clark,

    Could you provide a version without ClickOnce "pfx"? Otherwise it will report "Manifest" errors on my machine.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 17, 2019 6:03 AM
    Moderator
  • Hi Kyle,

    Sorry, I didn't think of that. Hopefully this will work.

    https://1drv.ms/u/s!AnzrNhs2zGELgaxeTTd9hgRRy_c5JA

    However, I think I discovered the issue. When I run the app as an administrator everything works like it should. When run from my Microsoft account is when files are not getting updated. I haven't done enough testing with it yet, but I think this is the problem.

    Monday, June 17, 2019 5:22 PM
  • Hi Clark,

    I am so sorry that it still has the error like the followed.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, June 18, 2019 9:40 AM
    Moderator