Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
修复PGC内容播放问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy committed Jun 1, 2023
1 parent c028b69 commit d424784
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/App/Assets/DashVideoTemplate.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static"
minBufferTime="{bufferTime}">
<MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static">
<Period start="PT0S">
<AdaptationSet group="1">
<ContentComponent contentType="audio" id="1" />
{audio}
</AdaptationSet>
<AdaptationSet group="2">
<ContentComponent contentType="video" id="2" />
<AdaptationSet>
<ContentComponent contentType="video" id="1" />
{video}
</AdaptationSet>
<AdaptationSet>
<ContentComponent contentType="audio" id="2" />
{audio}
</AdaptationSet>
</Period>
</MPD>
5 changes: 2 additions & 3 deletions src/App/Assets/DashVideoWithoutAudioTemplate.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static"
minBufferTime="{bufferTime}">
<MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static">
<Period start="PT0S">
<AdaptationSet group="1">
<AdaptationSet>
<ContentComponent contentType="video" id="1" />
{video}
</AdaptationSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private async Task<MediaInformation> InternalGetDashAsync(string cid, string aid
var isPgc = string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(seasonType);

var url = isPgc ? ApiConstants.Pgc.PlayInformation(proxy) : ApiConstants.Video.PlayInformation;
var requestType = isPgc ? RequestClientType.Web : RequestClientType.IOS;

var queryParameters = new Dictionary<string, string>
{
Expand Down Expand Up @@ -113,7 +114,7 @@ private async Task<MediaInformation> InternalGetDashAsync(string cid, string aid
otherQuery = $"area={area}";
}

var request = await _httpProvider.GetRequestMessageAsync(HttpMethod.Get, url, queryParameters, RequestClientType.IOS, additionalQuery: otherQuery);
var request = await _httpProvider.GetRequestMessageAsync(HttpMethod.Get, url, queryParameters, requestType, additionalQuery: otherQuery);
var response = await _httpProvider.SendAsync(request);
var data = await _httpProvider.ParseAsync<ServerResponse<PlayerInformation>, ServerResponse2<PlayerInformation>>(response, (str) =>
{
Expand Down
9 changes: 8 additions & 1 deletion src/Models/Models.Data/Player/SegmentInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public sealed class SegmentInformation
int width,
int height,
string initialization,
string indexRange)
string indexRange,
int startWithSap = 1)
{
Id = id;
BaseUrl = baseUrl;
Expand All @@ -44,6 +45,7 @@ public sealed class SegmentInformation
Height = height;
Initialization = initialization;
IndexRange = indexRange;
StartWithSap = startWithSap;
}

/// <summary>
Expand Down Expand Up @@ -96,6 +98,11 @@ public sealed class SegmentInformation
/// </summary>
public string IndexRange { get; }

/// <summary>
/// None.
/// </summary>
public int StartWithSap { get; }

/// <inheritdoc/>
public override bool Equals(object obj) => obj is SegmentInformation information && Id == information.Id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed partial class NativePlayerViewModel
private HttpClient GetVideoClient()
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Referer = new Uri("https://www.bilibili.com");
httpClient.DefaultRequestHeaders.Add("Referer", "https://www.bilibili.com");
httpClient.DefaultRequestHeaders.Add("User-Agent", ServiceConstants.DefaultUserAgentString);
return httpClient;
}
Expand All @@ -37,7 +37,7 @@ private async Task LoadDashVideoSourceAsync()
var mpdStr = await _fileToolkit.ReadPackageFile(mpdFilePath);

var videoStr =
$@"<Representation bandwidth=""{_video.Bandwidth}"" codecs=""{_video.Codecs}"" height=""{_video.Height}"" mimeType=""{_video.MimeType}"" id=""{_video.Id}"" width=""{_video.Width}"">
$@"<Representation bandwidth=""{_video.Bandwidth}"" codecs=""{_video.Codecs}"" height=""{_video.Height}"" mimeType=""{_video.MimeType}"" id=""{_video.Id}"" width=""{_video.Width}"" startWithSap=""{_video.StartWithSap}"">
<BaseURL></BaseURL>
<SegmentBase indexRange=""{_video.IndexRange}"">
<Initialization range=""{_video.Initialization}"" />
Expand Down Expand Up @@ -65,6 +65,7 @@ private async Task LoadDashVideoSourceAsync()

var stream = new MemoryStream(Encoding.UTF8.GetBytes(mpdStr)).AsInputStream();
var source = await AdaptiveMediaSource.CreateFromStreamAsync(stream, new Uri(_video.BaseUrl), "application/dash+xml", httpClient);
source.MediaSource.AdvancedSettings.AllSegmentsIndependent = true;
Debug.Assert(source.Status == AdaptiveMediaSourceCreationStatus.Success, "解析MPD失败");
source.MediaSource.DownloadRequested += (sender, args) =>
{
Expand Down

0 comments on commit d424784

Please sign in to comment.