来自WP中BackgroundAudioAgent的音乐和视频图像

时间:2013-11-23 10:56:42

标签: c# image menu windows-phone background-audio

我正在尝试在wp7中从BackgroundAudioAgent播放歌曲时在音乐和视频中设置图像!

我下载歌曲图片的代码是:

    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); }
                        }
                    };

我认为我的功能可以工作并下载图像 然后我使用此代码将其设置为AudioTrack类的AlbumArt:

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);

歌曲播放并显示标题名称和专辑名称,但音乐和视频中没有图像,为什么? 也许某些事情正在与共享媒体隔离,在某处我读到了这个?

1 个答案:

答案 0 :(得分:0)

解决方案是将图像放置到共享媒体目录,因此MediaHub可以访问内容!