コード例 #1
0
        /// <summary>
        /// ビデオをプレイリストに追加する
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public async Task AddVideoToPlaylist(string id)
        {
            // 入力の検証
            var playlistVm = this;
            var videoId    = id;

            if (playlistVm == null || string.IsNullOrEmpty(videoId))
            {
                return;
            }

            // 以下を参考にプレイリストに指定の動画を追加
            // https://github.com/youtube/api-samples/blob/master/dotnet/Google.Apis.YouTube.Samples.Playlists/PlaylistUpdates.cs#L94
            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            var playlistItem = new PlaylistItem();

            playlistItem.Snippet                    = new PlaylistItemSnippet();
            playlistItem.Snippet.PlaylistId         = playlistVm.Id;
            playlistItem.Snippet.ResourceId         = new ResourceId();
            playlistItem.Snippet.ResourceId.Kind    = "youtube#video";
            playlistItem.Snippet.ResourceId.VideoId = videoId;
            playlistItem = await service.PlaylistItems.Insert(playlistItem, "snippet").ExecuteAsync();

            PlaylistItemViewModels.Add(new PlaylistItemViewModel(playlistItem, this));
        }
コード例 #2
0
        /// <summary>
        /// プレイリストのアイテムを追加します
        /// </summary>
        /// <param name="vm">ViewModel</param>
        /// <returns></returns>
        internal async void AddPlaylistItem(PlaylistItemViewModel vm)
        {
            // 以下を参考にプレイリストに指定の動画を追加
            // https://github.com/youtube/api-samples/blob/master/dotnet/Google.Apis.YouTube.Samples.Playlists/PlaylistUpdates.cs#L94
            var factory = new YoutubeServiceFactory();
            var service = await factory.Create();

            var playlistItem = new PlaylistItem();

            playlistItem.Snippet            = new PlaylistItemSnippet();
            playlistItem.Snippet.PlaylistId = Playlist.Id;
            playlistItem.Snippet.ResourceId = vm.PlaylistItem.Snippet.ResourceId;
            playlistItem = await service.PlaylistItems.Insert(playlistItem, "snippet").ExecuteAsync();

            PlaylistItemViewModels.Add(new PlaylistItemViewModel(playlistItem, this));
        }