Solutions is to place images to shared media direcory, so MediaHub can have access to content!
Music and Videos image from BackgroundAudioAgent in WP
-
04-08-2022 - |
Pergunta
I am trying to set an image in Music and Videos when a song plays from BackgroundAudioAgent in wp7!
My code to download song's image is:
WebClient client = new WebClient();
client.CancelAsync();
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0)" + " (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
client.Headers[HttpRequestHeader.Referer] = constant.referer;
client.Headers[HttpRequestHeader.CacheControl] = "no-cache";
client.Headers[HttpRequestHeader.Pragma] = "no-cache";
client.OpenReadAsync(new Uri(constant.viewit3_start + file_in + constant.viewit3_stop));
//Stream Completed
client.OpenReadCompleted += (s, ex) =>
{
if (ex.Error == null)
{
try
{
//Get mp3 stream data
long file_bytes = ex.Result.Length;
//Check clever rules
if (file_bytes >= constant.bit)
{
//Isolated file
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(file_in + ".jpg", FileMode.Create, myIsolatedStorage))
{
try
{
using (BinaryWriter writer = new BinaryWriter(fileStream))
{
int readCount = 0;
byte[] buffer = new byte[32];
using (BinaryReader reader = new BinaryReader(ex.Result))
{
//Read file in chunks in order to reduce memory consumption and increase performance
while (readCount < file_bytes)
{
int actual = reader.Read(buffer, 0, buffer.Length);
readCount += actual;
writer.Write(buffer, 0, actual);
}
}
}
}
catch { if (show) { MessageBox.Show(constant.tile_again); } callback(false); }
}
}
callback(true);
}
else { callback(false); }
}
catch { callback(false); }
}
};
I think my function works and downloads images then i use this code to set it as AlbumArt of AudioTrack class:
AudioTrack audiotrack1 = new AudioTrack(new Uri(file_i + ".mp3", UriKind.Relative), name_i, album_name, string.Empty, new Uri(file_in + ".jpg", UriKind.Relative), byte_i, EnabledPlayerControls.All);
Song plays and shows title name and album name but no image in Music and Videos, why? Maybe something is going in with shared media isolated, somewhere i read about this?
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow