MediaPortal Forums HTPC/MediaCenter

Go Back   MediaPortal Forum » MediaPortal 1 » Community Skins and Plugins » Plugins


Plugins Plugins developed and maintained by users. Want to create your own plugin? Start a thread in here.

Reply
 
Thread Tools Display Modes
Old 2008-04-06, 15:56   #1 (permalink)
Portal Member
 
Join Date: Apr 2008
Posts: 26
Thanks: 2
Thanked 1 Time in 1 Post

Country:


Default How to Play a Playlist

it has come to my attention that using
Code:
MediaPortal.Player.g_Player.Play(whatever.mp3, MediaPortal.Player.g_Player.MediaType.Music)
will play an mp3 file

and it plays music perfectly, but with one major problem.

when i say put playlist.wpl instead of the .mp3 file above. the playlist plays, but MP plays it as a single file, so the song list does not appear in "current playlist" and i cannot go "next track"

any ideas?
hbe02 is offline   Reply With Quote
Old 2008-04-06, 16:08   #2 (permalink)
Portal Developer
 
and-81's Avatar
 
Join Date: Mar 2005
Location: Melbourne
Age: 27
Posts: 2,248
Thanks: 30
Thanked 140 Times in 88 Posts

Country:

My System

Default

What happens if you don't specify the MediaType?
and-81 is offline   Reply With Quote
Old 2008-04-06, 16:13   #3 (permalink)
Portal Member
 
Join Date: Apr 2008
Posts: 26
Thanks: 2
Thanked 1 Time in 1 Post

Country:


Default

Same thing, no difference.
hbe02 is offline   Reply With Quote
Old 2008-04-06, 16:32   #4 (permalink)
Portal Developer
 
and-81's Avatar
 
Join Date: Mar 2005
Location: Melbourne
Age: 27
Posts: 2,248
Thanks: 30
Thanked 140 Times in 88 Posts

Country:

My System

Default

hmm, I'll look into it further and get back to you ... in the meantime, check out the mediaportal source code and see how it's done there.
and-81 is offline   Reply With Quote
This User Say Thank You:
Old 2008-04-06, 17:02   #5 (permalink)
Portal Member
 
jburnette's Avatar
 
Join Date: Aug 2006
Location: Kentucky
Age: 23
Posts: 700
Thanks: 125
Thanked 90 Times in 49 Posts

Country:

My System

Default

I think that for playing a playlist you have to use the PlaylistPlayer Class in the Mediaportal.Playlists namespace. I've never actually used it, I just remember seeing it.
jburnette is offline   Reply With Quote
Old 2008-04-07, 23:07   #6 (permalink)
Portal Member
 
Join Date: Apr 2008
Posts: 26
Thanks: 2
Thanked 1 Time in 1 Post

Country:


Default

I looked around the class, cant find anything that works, i tried:
MediaPortal.Playlists.PlayListPlayer.SingletonPlay er.g_Player.Play(FileToPlay.Trim());

but that gave me the exact same result as before

btw i tried the following:
went to music folder
added an album to playlist
it was playing under current playlist and now playing perfectly and i can click next and that works
i treid "save" typed a name and pressed "done"
then i clicked "MY Playlists"
MP hangs for about 4 seconds then just resumes operation in current screen.. does not go to "My Playlists"
i tried searching with windows search for the playlist i entered..and i didnt find it.
any ideas?

Last edited by hbe02; 2008-04-07 at 23:11. Reason: Automerged Doublepost
hbe02 is offline   Reply With Quote
Old 2008-07-30, 02:47   #7 (permalink)
Portal Member
 
Join Date: Jul 2008
Location: Idaho
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post

Country:

My System

Default

Here is how I play a playlist:

Code:
using MediaPortal.Playlists;



public void PlayPlaylist(string playlistName)
        {
            PlayListPlayer playlistPlayer = PlayListPlayer.SingletonPlayer;
            playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC);

            string strPlayListPath = string.Empty;
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
            {
                strPlayListPath = xmlreader.GetValueAsString("music", "playlists", string.Empty);
                strPlayListPath = MediaPortal.Util.Utils.RemoveTrailingSlash(strPlayListPath);
            }
            string playlistFileName = Path.Combine(strPlayListPath, playlistName);
            PlayList tempPlaylist = GetPlaylistByPath(playlistFileName);

            if (!File.Exists(playlistFileName) && tempPlaylist != null)
                return;

            playlist.Clear();
            playlist.Name = tempPlaylist.Name;
            foreach (PlayListItem item in tempPlaylist)
            {
                playlist.Add(item);
            }

            if (playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC).Count > 0)
            {
                                playlistPlayer.Reset();
                                playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC;
                                playlistPlayer.Play(0);
             }
        }

private PlayList GetPlaylistByPath(string path)
        {
            IPlayListIO io;
            string ext = System.IO.Path.GetExtension(path);
            PlayList playlist = new PlayList();
            switch (ext.ToLower())
            {
                case ".m3u":
                    io = new PlayListM3uIO();
                    break;
                case ".pls":
                    io = new PlayListM3uIO();
                    break;
                case ".b4s":
                    io = new PlayListM3uIO();
                    break;
                case ".wpl":
                    io = new PlayListM3uIO();
                    break;
                default:
                    return playlist;
            }
            if (io.Load(playlist, path))
                return playlist;
            else
                return null;
        }
Hope it works for you,
Darick

If you are calling the above from a thread other than the main, then you may need to invoke it to run on the main thread, otherwise it could cause an error.

Code:
private delegate void PlayPlaylistHandler(string playlistName);
public void SomeMethod()
{
    string someplaylist = "someplaylist";
    System.Windows.Forms.Control currentform =     System.Windows.Forms.Form.FromHandle(GUIGraphicsContext.ActiveForm);

   if (currentform.InvokeRequired)
   {
        PlayPlaylistHandler handler = new PlayPlaylistHandler(PlayPlaylist);
        currentform.Invoke(handler, new object[] {someplaylist });
   }
   else
   {
        PlayPlaylist(someplaylist);
   }
Hope this helps,
Darick

Last edited by darick_c; 2008-07-30 at 03:22. Reason: Automerged Doublepost
darick_c is offline   Reply With Quote
Old 2008-08-03, 22:01   #8 (permalink)
Portal Member
 
Join Date: Jan 2008
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts

Country:

My System

Default

I have just been struggling with the same thing. I tried your code, Darick, but MP only plays the first file in the m3u playlist. When I open "current playlist" it is empty, and when I go to "now playing" there is no "next track" waiting. I want to be able to load an m3u playlist in code, and then skip back and forth between its tracks. Does this work with the code you posted? If so, I must be doing something wrong...
Fjoms is offline   Reply With Quote
Old 2008-08-03, 22:09   #9 (permalink)
Portal Member
 
jburnette's Avatar
 
Join Date: Aug 2006
Location: Kentucky
Age: 23
Posts: 700
Thanks: 125
Thanked 90 Times in 49 Posts

Country:

My System

Default

Fjoms, here's another method that may work for you:
Loading Current playlist, then Playing it
jburnette is offline   Reply With Quote
This User Say Thank You:
Old 2008-08-03, 22:32   #10 (permalink)
Portal Member
 
Join Date: Jan 2008
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts

Country:

My System

Default

That method certainly did the trick for me, jburnette, thanks!
Fjoms is offline   Reply With Quote
Reply

Bookmarks

Tags
playlist code

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Playlist error from Syntax M3U playlist file Luccio Support 9 Yesterday 23:38
'My Playlist', a better 'play all/random' fredklein Improvement Suggestions 0 2008-03-06 03:30
play radio and fav. playlist with one keystroke xpeet Newcomers Forum 0 2007-11-29 22:18
Display playlist name in Playlist view? Doodles Listen Music 0 2007-10-19 19:29
MyMusic: MP doesn't show playlist and crashes after loading large playlist The_Stig fixed 0.2.0.0 bugs 1 2006-09-15 09:32


All times are GMT +1. The time now is 06:21.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 Protected by Akismet Blog with WordPress