public void SearchMusicByName_InsideTest() { ANative_SearchArg s = new ANative_SearchArg(); s.Keywords = "bye bye bye"; IntPtr sptr = Marshal.AllocHGlobal(Marshal.SizeOf(s)); var api = new QQMusicAPI(); //SearchResult result = api.SearchAsync(new SearchArg() { Keywords = "bye bye bye" }).Result; Marshal.StructureToPtr(s, sptr, false); byte[] buff = new byte[10000]; unsafe { fixed(byte *v = &buff[0]) { IntPtr ptr = new IntPtr(v); Wrapper.SearchMusicByName_Inside(sptr, ptr); Native_SearchResult *f = (Native_SearchResult *)(ptr); var songItem = Marshal.PtrToStructure <Native_SongItem>(ptr + 12); Assert.NotNull(songItem.singer_name); } } }
public void DownloadMusic_InsideTest() { ANative_SearchArg s = new ANative_SearchArg(); s.Keywords = "bye bye bye"; IntPtr sptr = Marshal.AllocHGlobal(Marshal.SizeOf(s)); var api = new QQMusicAPI(); //SearchResult result = api.SearchAsync(new SearchArg() { Keywords = "bye bye bye" }).Result; Marshal.StructureToPtr(s, sptr, false); byte[] buff = new byte[10000]; unsafe { fixed(byte *v = &buff[0]) { IntPtr ptr = new IntPtr(v); Wrapper.SearchMusicByName_Inside(sptr, ptr); Native_SearchResult *f = (Native_SearchResult *)(ptr); var songItem = Marshal.PtrToStructure <Native_SongItem>(ptr + 12); //Assert.Equal("Lovestoned", songItem.singer_name); string dir = @""; var dirptr = Marshal.StringToCoTaskMemUni(dir); var r = Wrapper.DownloadMusic_Inside(ptr + 12, EnumFileType.Mp3_128k, dirptr, dir.Length); Assert.True(r); } } }
public async void DownloadAsyncTest() { var api = new QQMusicAPI(); var arg = new SearchArg() { Keywords = "ɳĮÂæÍÕ" }; arg.PageSize = 30; var result = await api.SearchAsync(arg); //ËÑË÷ËÑË÷²¢»ñÈ¡½á¹û Assert.NotNull(result); Assert.NotNull(result.song); Assert.NotEmpty(result.song.list); }
public static bool SearchMusicByName_Inside(IntPtr SearchArgPtr, IntPtr testptr) { //Console.WriteLine("SearchArgPtr:{0:X}", SearchArgPtr); var api = new QQMusicAPI(); var searchArg = Marshal.PtrToStructure <ANative_SearchArg>(SearchArgPtr); try { SearchResult result = api.SearchAsync(searchArg).Result; int offset = 0; SearchResultExtend.WriteTo(result, testptr, ref offset); return(true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } }
public Form1() { InitializeComponent(); api = new QQMusicAPI(); var dir = new FileInfo(this.GetType().Assembly.Location).Directory.FullName; var libDirectory = new DirectoryInfo(Path.Combine(dir, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64")); var options = new string[] { // VLC options can be given here. Please refer to the VLC command line documentation. }; mediaPlayer = new Vlc.DotNet.Core.VlcMediaPlayer(libDirectory); mediaPlayer.Buffering += MediaPlayer_Buffering; mediaPlayer.EndReached += MediaPlayer_EndReached; mediaPlayer.MediaChanged += MediaPlayer_MediaChanged; mediaPlayer.Playing += MediaPlayer_Playing; mediaPlayer.Stopped += MediaPlayer_Stopped; mediaPlayer.TimeChanged += MediaPlayer_TimeChanged; this.FormClosing += (a, b) => mediaPlayer.Dispose(); }
public static bool DownloadMusic_Inside(IntPtr Native_SongItemPtr, EnumFileType type, IntPtr dirPtr, int dirlength) { try { Native_SongItem nsi = Marshal.PtrToStructure <Native_SongItem>(Native_SongItemPtr); string dir = null; unsafe { dir = new string((char *)dirPtr.ToPointer(), 0, dirlength); } Console.WriteLine($"准备下载{nsi.name.RemoveUnicodeEnd()}到{dir}"); //转换 ISongItem si = SearchResultExtend.ToSongItem(nsi); var api = new QQMusicAPI(); api.downloadSongAsync(si, dir, type).Wait(); api.downloadLyricAsync(si, dir).Wait(); return(true); } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
static void Main(string[] args) { var api = new QQMusicAPI(); //初始化一个实例 string songName = null; while (string.IsNullOrEmpty(songName)) { songName = GetUserInput("\r\n请输入要搜索的歌名"); } var arg = new SearchArg() { Keywords = songName }; arg.PageSize = 30; var result = api.SearchAsync(arg).Result; //搜索搜索并获取结果 if (result.song.list.Count > 0) { Console.WriteLine($"共搜索到{result.song.list.Count}个结果"); //为了简化示例,就取列表的第一条歌曲 var song = result.song.list[0]; EnumFileType type = song.file.GetAvailableFileType();//取当前歌曲可用的类型 Console.WriteLine(type); //获取当前目录用来存放音乐 string dir = AppContext.BaseDirectory; //要下载哪种类型的音乐呢? EnumFileType downloadType = 0; downloadType |= (type & EnumFileType.Ape); if (downloadType == 0) { downloadType |= (type & EnumFileType.Flac); } if (downloadType == 0) { downloadType |= (type & EnumFileType.Mp3_320k); } if (downloadType == 0) { downloadType |= (type & EnumFileType.Mp3_128k); } if (downloadType == 0) { downloadType |= (type & EnumFileType.M4a); } var t = api.downloadSongAsync(song, dir, downloadType);//建立下载的task,下载文件最大并保存到当前目录 //可选:当然也可以尝试lrc的歌词下载下来 var t2 = api.downloadLyricAsync(song, dir); Console.WriteLine("Start download:"); while (!t.IsCompleted) { Console.Write("."); System.Threading.Thread.Sleep(500); } t2.Wait(); Console.WriteLine(); if (t.IsFaulted) { Console.WriteLine($"Error:{t.Exception.Message}"); } else { Console.WriteLine("Download success!"); } } else { Console.WriteLine("没找到你需要的歌曲"); } Console.WriteLine("按任意键退出本示例"); Console.ReadKey(); }