Ejemplo n.º 1
0
 public async Task<string> BroadcastChannelAsync(int yellowPageId, string sourceUri, string sourceStream, string contentReader,
     string name, string url, int bitrate, string mimeType, string genre, string desc, string comment,
     string trackName, string trackCreator, string trackGenre, string trackAlbum, string trackUrl)
 {
     var jsonObject = DynamicJson.Serialize(new
     {
         yellowPageId = yellowPageId,
         sourceUri = sourceUri,
         sourceStream = sourceStream,
         contentReader = contentReader,
         info = new
         {
             name = name,
             url = url,
             bitrate = bitrate,
             mimeType = mimeType,
             genre = genre,
             desc = desc,
             comment = comment,
         },
         track = new
         {
             name = trackName,
             creator = trackCreator,
             genre = trackGenre,
             album = trackAlbum,
             url = trackUrl
         }
     });
     var json = DynamicJson.Parse(await UploadAsync(ApiUrl, GetJsonRpc("broadcastChannel", jsonObject)));
     if (!json.IsDefined("result"))
     {
         var status = new XmlStatus(GetViewXmlAsync().Result);
         var id = status.GetChannelId(name);
         if (id == PeerCast.NullId)
             throw new PeerCastException("PeerCastがエラーを返しました:" + Environment.NewLine + json.error.message);
         return id;
     }
     return json.result;
 }
Ejemplo n.º 2
0
        public override Task<Tuple<string, int>> BroadcastAsync(YellowPages yellowPages, BroadcastParameter parameter)
        {
            return Task.Factory.StartNew(() =>
            {
                using (var dao = new PeercastDao(Address))
                {
                    SetYellowPagesAwait(dao, yellowPages.Url);

                    var status = new XmlStatus(dao.GetViewXmlAsync().Result);
                    if (status.Exists(parameter.Name))
                    {
                        throw new PeerCastException("同名のチャンネルが既にあります。");
                    }

                    dao.FetchAsync(parameter.StreamUrl, parameter.Name, parameter.Genre, parameter.Description,
                        parameter.ContactUrl, parameter.Type).Wait();
                    var tuple = Repeat(() =>
                    {
                        var afterStatus = new XmlStatus(dao.GetViewXmlAsync().Result);
                        return GetChannelInfo(afterStatus, parameter.Name);
                    });
                    if (NullId == tuple.Item1)
                    {
                        dao.StopAsync(tuple.Item1).Wait();
                        throw new PeerCastException("チャンネルの作成に失敗しました。" + Environment.NewLine
                            + "エンコードが開始されているか、またはストリームURLが正しいか確認してください。");
                    }

                    dao.SetMetaAsync(parameter.Name, parameter.Genre, parameter.Description,
                        parameter.ContactUrl, parameter.Comment,
                        parameter.TrackArtist, parameter.TrackTitle, parameter.TrackAlbum,
                        parameter.TrackGenre, parameter.TrackContact).Wait();
                    return tuple;
                }
            });
        }
Ejemplo n.º 3
0
 private Tuple<string, int> GetChannelInfo(XmlStatus status, string name)
 {
     return Tuple.Create(status.GetChannelId(name), status.GetBitrate(name));
 }