/// <summary> /// 获取播放地址 /// </summary> /// <param name="vodeoId">视频ID</param> public static void GetPlayUrl(string videoId) { try { // 构造请求 GetPlayInfoRequest request = new GetPlayInfoRequest(); request.VideoId = videoId; // request.AuthTimeout = 3600; // 初始化客户端 //DefaultAcsClient client = InitVodClient(); // 发起请求,并得到 response GetPlayInfoResponse response = client.GetAcsResponse(request); //获取封面图片 videoImgUrl = response.VideoBase.CoverURL; List <GetPlayInfoResponse.GetPlayInfo_PlayInfo> playInfoList = response.PlayInfoList; foreach (var playInfo in response.PlayInfoList) { if (playInfo.Format == "m3u8") { videoUrl = playInfo.PlayURL; //获取视频的播放地址 } } } catch (ServerException ex) { Console.WriteLine(ex.ToString()); } catch (ClientException ex) { Console.WriteLine(ex.ToString()); } }
public static GetPlayInfoResponse Unmarshall(UnmarshallerContext context) { GetPlayInfoResponse getPlayInfoResponse = new GetPlayInfoResponse(); getPlayInfoResponse.HttpResponse = context.HttpResponse; getPlayInfoResponse.RequestId = context.StringValue("GetPlayInfo.RequestId"); GetPlayInfoResponse.GetPlayInfo_VideoBase videoBase = new GetPlayInfoResponse.GetPlayInfo_VideoBase(); videoBase.OutputType = context.StringValue("GetPlayInfo.VideoBase.OutputType"); videoBase.CoverURL = context.StringValue("GetPlayInfo.VideoBase.CoverURL"); videoBase.Duration = context.StringValue("GetPlayInfo.VideoBase.Duration"); videoBase.Status = context.StringValue("GetPlayInfo.VideoBase.Status"); videoBase.Title = context.StringValue("GetPlayInfo.VideoBase.Title"); videoBase.VideoId = context.StringValue("GetPlayInfo.VideoBase.VideoId"); videoBase.MediaType = context.StringValue("GetPlayInfo.VideoBase.MediaType"); videoBase.CreationTime = context.StringValue("GetPlayInfo.VideoBase.CreationTime"); videoBase.TranscodeMode = context.StringValue("GetPlayInfo.VideoBase.TranscodeMode"); List <GetPlayInfoResponse.GetPlayInfo_VideoBase.GetPlayInfo_Thumbnail> videoBase_thumbnailList = new List <GetPlayInfoResponse.GetPlayInfo_VideoBase.GetPlayInfo_Thumbnail>(); for (int i = 0; i < context.Length("GetPlayInfo.VideoBase.ThumbnailList.Length"); i++) { GetPlayInfoResponse.GetPlayInfo_VideoBase.GetPlayInfo_Thumbnail thumbnail = new GetPlayInfoResponse.GetPlayInfo_VideoBase.GetPlayInfo_Thumbnail(); thumbnail.URL = context.StringValue("GetPlayInfo.VideoBase.ThumbnailList[" + i + "].URL"); videoBase_thumbnailList.Add(thumbnail); } videoBase.ThumbnailList = videoBase_thumbnailList; getPlayInfoResponse.VideoBase = videoBase; List <GetPlayInfoResponse.GetPlayInfo_PlayInfo> getPlayInfoResponse_playInfoList = new List <GetPlayInfoResponse.GetPlayInfo_PlayInfo>(); for (int i = 0; i < context.Length("GetPlayInfo.PlayInfoList.Length"); i++) { GetPlayInfoResponse.GetPlayInfo_PlayInfo playInfo = new GetPlayInfoResponse.GetPlayInfo_PlayInfo(); playInfo.Width = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Width"); playInfo.Height = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Height"); playInfo.Size = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Size"); playInfo.PlayURL = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].PlayURL"); playInfo.Bitrate = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Bitrate"); playInfo.Definition = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Definition"); playInfo.Duration = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Duration"); playInfo.Format = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Format"); playInfo.Fps = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Fps"); playInfo.Encrypt = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Encrypt"); playInfo.Plaintext = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Plaintext"); playInfo.Complexity = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Complexity"); playInfo.StreamType = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].StreamType"); playInfo.Rand = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Rand"); playInfo.JobId = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].JobId"); playInfo.PreprocessStatus = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].PreprocessStatus"); playInfo.WatermarkId = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].WatermarkId"); playInfo.Status = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Status"); getPlayInfoResponse_playInfoList.Add(playInfo); } getPlayInfoResponse.PlayInfoList = getPlayInfoResponse_playInfoList; return(getPlayInfoResponse); }
/// <summary> /// 获取视频播放地址 /// </summary> /// <param name="request"></param> /// <returns></returns> public GetPlayInfoResponse GetPlayInfo(GetPlayInfoRequest request) { GetPlayInfoResponse response = new GetPlayInfoResponse(); try { response = acsClient.GetAcsResponse(request); } catch (Exception ex) { } return(response); }
/// <summary> /// 获取视频的播放信息 /// </summary> /// <param name="input">参数:https://help.aliyun.com/document_detail/56124.html?spm=a2c4g.11186623.2.14.140f6872F2JNHX</param> public GetPlayInfoResponse GetPlayInfo(GetPlayInfoRequest input) { var client = InitVodClient(); // 发起请求,并得到 response try { GetPlayInfoResponse response = client.GetAcsResponse(input); return(response); } catch (Exception e) { Console.WriteLine(e); throw new UserFriendlyException($"获取视频信息报错:{e.Message}"); } }
public static GetPlayInfoResponse Unmarshall(UnmarshallerContext context) { GetPlayInfoResponse getPlayInfoResponse = new GetPlayInfoResponse(); getPlayInfoResponse.HttpResponse = context.HttpResponse; getPlayInfoResponse.RequestId = context.StringValue("GetPlayInfo.RequestId"); GetPlayInfoResponse.GetPlayInfo_VideoBase videoBase = new GetPlayInfoResponse.GetPlayInfo_VideoBase(); videoBase.CoverURL = context.StringValue("GetPlayInfo.VideoBase.CoverURL"); videoBase.Duration = context.StringValue("GetPlayInfo.VideoBase.Duration"); videoBase.Status = context.StringValue("GetPlayInfo.VideoBase.Status"); videoBase.Title = context.StringValue("GetPlayInfo.VideoBase.Title"); videoBase.VideoId = context.StringValue("GetPlayInfo.VideoBase.VideoId"); videoBase.MediaType = context.StringValue("GetPlayInfo.VideoBase.MediaType"); videoBase.CreationTime = context.StringValue("GetPlayInfo.VideoBase.CreationTime"); getPlayInfoResponse.VideoBase = videoBase; List <GetPlayInfoResponse.GetPlayInfo_PlayInfo> getPlayInfoResponse_playInfoList = new List <GetPlayInfoResponse.GetPlayInfo_PlayInfo>(); for (int i = 0; i < context.Length("GetPlayInfo.PlayInfoList.Length"); i++) { GetPlayInfoResponse.GetPlayInfo_PlayInfo playInfo = new GetPlayInfoResponse.GetPlayInfo_PlayInfo(); playInfo.Width = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Width"); playInfo.Height = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Height"); playInfo.Size = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Size"); playInfo.PlayURL = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].PlayURL"); playInfo.Bitrate = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Bitrate"); playInfo.Definition = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Definition"); playInfo.Duration = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Duration"); playInfo.Format = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Format"); playInfo.Fps = context.StringValue("GetPlayInfo.PlayInfoList[" + i + "].Fps"); playInfo.Encrypt = context.LongValue("GetPlayInfo.PlayInfoList[" + i + "].Encrypt"); getPlayInfoResponse_playInfoList.Add(playInfo); } getPlayInfoResponse.PlayInfoList = getPlayInfoResponse_playInfoList; return(getPlayInfoResponse); }