mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
youtube playlists random play support
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Android.App;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Media;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Support.V4.Media.Session;
|
||||
using Android.Graphics;
|
||||
using MusicApp.Resources.values;
|
||||
using Android.Database;
|
||||
using Android.Graphics;
|
||||
using Android.Media;
|
||||
using Android.OS;
|
||||
using Android.Provider;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Square.Picasso;
|
||||
|
||||
using Uri = Android.Net.Uri;
|
||||
using Android.Support.V4.Media.Session;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Widget;
|
||||
using Com.Google.Android.Exoplayer2;
|
||||
using Com.Google.Android.Exoplayer2.Extractor;
|
||||
using Com.Google.Android.Exoplayer2.Source;
|
||||
using Com.Google.Android.Exoplayer2.Trackselection;
|
||||
using Com.Google.Android.Exoplayer2.Upstream;
|
||||
using Com.Google.Android.Exoplayer2.Source;
|
||||
using Com.Google.Android.Exoplayer2.Extractor;
|
||||
using MusicApp.Resources.values;
|
||||
using Square.Picasso;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using YoutubeExplode;
|
||||
using YoutubeExplode.Models.MediaStreams;
|
||||
using Uri = Android.Net.Uri;
|
||||
|
||||
namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
@@ -279,8 +280,17 @@ namespace MusicApp.Resources.Portable_Class
|
||||
SwitchQueue(next);
|
||||
}
|
||||
|
||||
public void SwitchQueue(Song song)
|
||||
public async void SwitchQueue(Song song)
|
||||
{
|
||||
if (!song.isParsed)
|
||||
{
|
||||
YoutubeClient client = new YoutubeClient();
|
||||
var videoInfo = await client.GetVideoAsync(song.GetPath());
|
||||
AudioStreamInfo streamInfo = videoInfo.AudioStreamInfos.OrderBy(s => s.Bitrate).Last();
|
||||
song.SetPath(streamInfo.Url);
|
||||
song.isParsed = true;
|
||||
}
|
||||
|
||||
Play(song, false);
|
||||
|
||||
if (Player.instance != null)
|
||||
@@ -584,10 +594,16 @@ namespace MusicApp.Resources.Portable_Class
|
||||
Console.WriteLine("Error in playback resetting: " + args.Cause);
|
||||
}
|
||||
|
||||
public void OnPlayerStateChanged(bool p0, int p1)
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
public void OnPlayerStateChanged(bool playWhenReady, int state)
|
||||
{
|
||||
|
||||
if (state == ExoPlayer.StateEnded)
|
||||
{
|
||||
PlayNext();
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
|
||||
|
||||
public void OnPositionDiscontinuity()
|
||||
{
|
||||
|
||||
@@ -164,6 +164,25 @@ namespace MusicApp.Resources.Portable_Class
|
||||
MainActivity.instance.SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, Player.NewInstance()).Commit();
|
||||
}
|
||||
|
||||
public static async void PlayFiles(Song[] files)
|
||||
{
|
||||
if (files.Length < 1)
|
||||
return;
|
||||
|
||||
Play(files[0].GetPath());
|
||||
|
||||
if (files.Length < 2)
|
||||
return;
|
||||
|
||||
await Task.Delay(10000);
|
||||
|
||||
for(int i = 1; i < files.Length; i++)
|
||||
{
|
||||
MusicPlayer.queue.Add(files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static async void PlayNext(string videoID)
|
||||
{
|
||||
YoutubeClient client = new YoutubeClient();
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
async void RandomPlay(string playlistID)
|
||||
{
|
||||
List<string> tracksPath = new List<string>();
|
||||
List<Song> tracks = new List<Song>();
|
||||
string nextPageToken = "";
|
||||
while (nextPageToken != null)
|
||||
{
|
||||
@@ -179,16 +179,14 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
foreach (var item in ytPlaylist.Items)
|
||||
{
|
||||
tracksPath.Add(item.Id);
|
||||
Song song = new Song(item.Snippet.Title, item.Snippet.ChannelTitle, item.Snippet.Thumbnails.Default__.Url, -1, -1, item.Id, true, false);
|
||||
tracks.Add(song);
|
||||
}
|
||||
|
||||
nextPageToken = ytPlaylist.NextPageToken;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Android.App.Application.Context, typeof(MusicPlayer));
|
||||
intent.PutStringArrayListExtra("files", tracksPath);
|
||||
intent.SetAction("RandomPlay");
|
||||
Activity.StartService(intent);
|
||||
YoutubeEngine.PlayFiles(tracks.ToArray());
|
||||
}
|
||||
|
||||
void Rename(int position, string playlistID)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
private long id;
|
||||
private string path;
|
||||
private bool isYT;
|
||||
public bool isParsed;
|
||||
|
||||
public string GetName() { return Name; }
|
||||
public string GetArtist() { return Artist; }
|
||||
@@ -19,7 +20,7 @@
|
||||
public string GetPath() { return path; }
|
||||
public bool IsYt { get { return isYT; } }
|
||||
|
||||
public Song(string Name, string Artist, string Album, long AlbumArt, long id, string path, bool isYT = false)
|
||||
public Song(string Name, string Artist, string Album, long AlbumArt, long id, string path, bool isYT = false, bool isParsed = true)
|
||||
{
|
||||
this.Name = Name;
|
||||
this.Artist = Artist;
|
||||
@@ -28,8 +29,10 @@
|
||||
this.id = id;
|
||||
this.path = path;
|
||||
this.isYT = isYT;
|
||||
this.isParsed = isParsed;
|
||||
}
|
||||
|
||||
public void SetName(string Name) { this.Name = Name; }
|
||||
public void SetPath(string path) { this.path = path; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user