How come playing a playlist with a DRM song makes the MediaPlayer dead in the water? It doesn't do anything... it just sits there. What is bad about this is that there is no built-in way to play a user's playlist unless all the songs are not DRM. Might be nice for us, but not fun for Zune people. How about making the MediaPlayer just ignore the DRM songs while in game? Or allow us to make a playlist / song collection on the fly?
Instead we have to manually play each song on the fly... So here is a Connect item I started..
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=343208&SiteID=226
Here is some code that skips DRM songs...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
using System; using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Media;
namespace FocusedGames.GW3 { class MusicPlayer : GameComponent { public bool isRepeating = false;
public MusicPlayer(Game game) : base (game) { game.Services.AddService(typeof(MusicPlayer), this);
#if ZUNE isRepeating = MediaPlayer.IsRepeating; MediaPlayer.IsRepeating = false; #endif }
protected override void Dispose(bool disposing) { base.Dispose(disposing);
#if ZUNE MediaPlayer.IsRepeating = isRepeating; #endif }
#if ZUNE private Queue<Song> songQueue = new Queue<Song>(); private Song currentSong = null;
public void AddToQueue(Song song) { if (song.IsProtected) return;
/* if (songQueue.Contains(song)) return; */
songQueue.Enqueue(song); }
public void AddToQueue(Playlist playlist) { for (int i = 0; i < playlist.Songs.Count; i++) AddToQueue(playlist.Songs ); }
public void ClearQueue() { songQueue.Clear(); }
public override void Update(GameTime gameTime) { base.Update(gameTime);
if (MediaPlayer.State == MediaState.Paused) { if (currentSong == null) MediaPlayer.Resume(); else MoveToNextSong(); } else if (MediaPlayer.State == MediaState.Stopped) { MoveToNextSong(); } }
public void MoveToNextSong() { if (songQueue.Count > 0) { currentSong = songQueue.Dequeue();
MediaPlayer.Play(currentSong); } } #endif } } |
John Sedlak Xna/DirectX MVP
Focused Games |
My Blog