As I mentioned on twitter, in Windows Phone 8 you can add or remove songs from the device's music library using MediaLibraryExtensions. The new capability is mentioned on MSDN here. However, I couldn't find any documentation for the APIs, so here's the API printout for the new Microsoft.Xna.Framework.MediaLibraryExtensions.dll:
//Microsoft.Xna.Framework.MediaLibraryExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553
namespace Microsoft.Xna.Framework.Media.PhoneExtensions {
public static class MediaLibraryExtensions {
public static void Delete(MediaLibrary library, Song song);
public static String GetPath(Picture picture);
public static String GetPathFromToken(MediaLibrary library, String token);
public static Stream GetPreviewImage(Picture picture);
public static Song SaveSong(MediaLibrary library, Uri filename, SongMetadata songMetadata, SaveSongOperation operation);
}
public enum SaveSongOperation {
CopyToLibrary,
MoveToLibrary
}
public sealed class SongMetadata {
public SongMetadata();
public Uri AlbumArtistBackgroundUri { get; set; }
public String AlbumArtistName { get; set; }
public Uri AlbumArtUri { get; set; }
public String AlbumName { get; set; }
public DateTime AlbumReleaseDate { get; set; }
public Uri ArtistBackgroundUri { get; set; }
public String ArtistName { get; set; }
public TimeSpan Duration { get; set; }
public String GenreName { get; set; }
public String Name { get; set; }
public Int32 TrackNumber { get; set; }
}
}
You can use this new API by invoking SaveSong with a local URI and by potentially overriding the ID3 metadata by including a custom SongMetadata. This API only allows you to store new songs, but I guess you can group your podcasts under a factious artist. Quick note about this API is to make sure to add the new DLL reference MediaLibraryExtensions DLL. You can also can keep SongMetadata as null and have the WP8 OS infer ID3 metadata.
Here's a simple code snippet:
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var sourceFile = await Package.Current.InstalledLocation.GetFileAsync("ChargeOfTheLightBridge.mp3");
CopyFileIntoIsoStore(sourceFile);
var library = new MediaLibrary();
library.SaveSong(new Uri(sourceFile.Name, UriKind.RelativeOrAbsolute),
new SongMetadata()
{
ArtistName = "My Custom Artist",
AlbumArtistName = "My Custom Artist",
Name = "My Custom Track Name",
AlbumName = "clubbing baby seals in the face",
Duration = TimeSpan.FromSeconds(29),
TrackNumber = 1,
AlbumReleaseDate = DateTime.Now,
GenreName = "Podcasts"
},
SaveSongOperation.CopyToLibrary);
}
private async void CopyFileIntoIsoStore(StorageFile sourceFile)
{
using (var s = await sourceFile.OpenReadAsync())
using (var dr = new DataReader(s))
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
using (var targetFile = isoStore.CreateFile(sourceFile.Name))
{
var data = new byte[s.Size];
await dr.LoadAsync((uint) s.Size);
dr.ReadBytes(data);
targetFile.Write(data, 0, data.Length);
}
}
Note that we had to save a file in IsoStore to use this API. Also note that the Uri isn't well-formed or in a standard IsoStore Uri. It's just the file name.
When we run this code snippet we can see the following: