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 Android.App;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Android.App;
|
|
||||||
using Android.Content;
|
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.Database;
|
||||||
|
using Android.Graphics;
|
||||||
|
using Android.Media;
|
||||||
|
using Android.OS;
|
||||||
using Android.Provider;
|
using Android.Provider;
|
||||||
using System.Linq;
|
using Android.Support.V4.Media.Session;
|
||||||
using System.Threading.Tasks;
|
using Android.Support.V7.App;
|
||||||
using Square.Picasso;
|
|
||||||
|
|
||||||
using Uri = Android.Net.Uri;
|
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using Com.Google.Android.Exoplayer2;
|
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.Trackselection;
|
||||||
using Com.Google.Android.Exoplayer2.Upstream;
|
using Com.Google.Android.Exoplayer2.Upstream;
|
||||||
using Com.Google.Android.Exoplayer2.Source;
|
using MusicApp.Resources.values;
|
||||||
using Com.Google.Android.Exoplayer2.Extractor;
|
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
|
namespace MusicApp.Resources.Portable_Class
|
||||||
{
|
{
|
||||||
@@ -279,8 +280,17 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
SwitchQueue(next);
|
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);
|
Play(song, false);
|
||||||
|
|
||||||
if (Player.instance != null)
|
if (Player.instance != null)
|
||||||
@@ -584,10 +594,16 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
Console.WriteLine("Error in playback resetting: " + args.Cause);
|
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()
|
public void OnPositionDiscontinuity()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -164,6 +164,25 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
MainActivity.instance.SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, Player.NewInstance()).Commit();
|
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)
|
public static async void PlayNext(string videoID)
|
||||||
{
|
{
|
||||||
YoutubeClient client = new YoutubeClient();
|
YoutubeClient client = new YoutubeClient();
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
|
|
||||||
async void RandomPlay(string playlistID)
|
async void RandomPlay(string playlistID)
|
||||||
{
|
{
|
||||||
List<string> tracksPath = new List<string>();
|
List<Song> tracks = new List<Song>();
|
||||||
string nextPageToken = "";
|
string nextPageToken = "";
|
||||||
while (nextPageToken != null)
|
while (nextPageToken != null)
|
||||||
{
|
{
|
||||||
@@ -179,16 +179,14 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
|
|
||||||
foreach (var item in ytPlaylist.Items)
|
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;
|
nextPageToken = ytPlaylist.NextPageToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(Android.App.Application.Context, typeof(MusicPlayer));
|
YoutubeEngine.PlayFiles(tracks.ToArray());
|
||||||
intent.PutStringArrayListExtra("files", tracksPath);
|
|
||||||
intent.SetAction("RandomPlay");
|
|
||||||
Activity.StartService(intent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rename(int position, string playlistID)
|
void Rename(int position, string playlistID)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
private long id;
|
private long id;
|
||||||
private string path;
|
private string path;
|
||||||
private bool isYT;
|
private bool isYT;
|
||||||
|
public bool isParsed;
|
||||||
|
|
||||||
public string GetName() { return Name; }
|
public string GetName() { return Name; }
|
||||||
public string GetArtist() { return Artist; }
|
public string GetArtist() { return Artist; }
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
public string GetPath() { return path; }
|
public string GetPath() { return path; }
|
||||||
public bool IsYt { get { return isYT; } }
|
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.Name = Name;
|
||||||
this.Artist = Artist;
|
this.Artist = Artist;
|
||||||
@@ -28,8 +29,10 @@
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.isYT = isYT;
|
this.isYT = isYT;
|
||||||
|
this.isParsed = isParsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetName(string Name) { this.Name = Name; }
|
public void SetName(string Name) { this.Name = Name; }
|
||||||
|
public void SetPath(string path) { this.path = path; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user