// MonoGame - Copyright (C) MonoGame Foundation, Inc // This file is subject to the terms and conditions defined in // file 'LICENSE.txt', which is part of this source code package. using System; using System.IO; namespace Microsoft.Xna.Framework.Media { /// /// Provides access to a song in the song library. /// public sealed partial class Song : IEquatable, IDisposable { private string _name; private string _filePath; private int _playCount = 0; private TimeSpan _duration = TimeSpan.Zero; bool disposed; /// /// Gets the on which the Song appears. /// public Album Album { get { return PlatformGetAlbum(); } } /// /// Gets the of the Song. /// public Artist Artist { get { return PlatformGetArtist(); } } /// /// Gets the of the Song. /// public Genre Genre { get { return PlatformGetGenre(); } } /// /// Gets a value indicating whether the object is disposed. /// public bool IsDisposed { get { return disposed; } } #if ANDROID || OPENAL || WEB || IOS || NATIVE || NO_AUDIO internal delegate void FinishedPlayingHandler(object sender, EventArgs args); #if !DESKTOPGL event FinishedPlayingHandler DonePlaying; #endif #endif internal Song(string fileName, int durationMS) : this(fileName) { _duration = TimeSpan.FromMilliseconds(durationMS); } internal Song(string fileName) { _filePath = fileName; _name = Path.GetFileNameWithoutExtension(fileName); PlatformInitialize(fileName); } /// ~Song() { Dispose(false); } internal string FilePath { get { return _filePath; } } /// /// Returns a song that can be played via . /// /// The name for the song. See Song.Name. /// The path to the song file. /// public static Song FromUri(string name, Uri uri) { var song = new Song(uri.OriginalString); song._name = name; return song; } /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } void Dispose(bool disposing) { if (!disposed) { if (disposing) { PlatformDispose(disposing); } disposed = true; } } /// /// Gets the hash code for this instance. /// public override int GetHashCode () { return base.GetHashCode (); } /// /// Determines whether two instances of are equal. /// /// The to compare with the current object /// if the specified is equal to the current object; /// otherwise, public bool Equals(Song song) { #if DIRECTX return song != null && song.FilePath == FilePath; #else return ((object)song != null) && (Name == song.Name); #endif } /// public override bool Equals(Object obj) { if(obj == null) { return false; } return Equals(obj as Song); } /// /// Determines whether the specified Song instances are equal. /// public static bool operator ==(Song song1, Song song2) { if((object)song1 == null) { return (object)song2 == null; } return song1.Equals(song2); } /// /// Determines whether the specified Song instances are not equal. /// public static bool operator !=(Song song1, Song song2) { return !(song1 == song2); } /// /// Gets the duration of the . /// public TimeSpan Duration { get { return _duration; } } /// /// Gets a value that indicates whether the song is DRM protected content. /// public bool IsProtected { get { return PlatformIsProtected(); } } /// /// Gets a value that indicates whether the song has been rated by the user. /// public bool IsRated { get { return PlatformIsRated(); } } /// /// Gets the name of the . /// public string Name { get { return _name; } } /// /// Gets the song play count. /// public int PlayCount { get { return PlatformGetPlayCount(); } } /// /// Gets the user's rating for the . /// /// /// User's rating for this , or 0 if the song is unrated. /// Ratings range from 1 (dislike the most) to 10 (like the most). /// public int Rating { get { return PlatformGetRating(); } } /// /// Gets the track number of the song on the song's . /// /// /// Track number of this on the song's . /// public int TrackNumber { get { return PlatformGetTrackNumber(); } } } }