我遇到的问题是我的 Android SurfaceViewRenderer 的 Xamarin Forms 自定义渲染器与它显示的远程视频的纵横比不同。这会导致视频两边的相等部分被切断。我曾尝试查看 SurfaceViewRenderer 的 SurfaceChanged 事件,但宽度和高度与 SurfaceView 本身有关,而不是与它作为接收器的视频轨道有关。
在我的对等连接观察器的 OnAddStream 函数中,我可以看到 MediaStream 对象和相关的远程 VideoTrack。这是我认为最相关的代码区域:
public void OnAddStream(MediaStream p0)
{
System.Diagnostics.Debug.WriteLine($"{nameof(OnAddStream)}");
try
{
var videoTracks = p0.VideoTracks.OfType<VideoTrack>();
videoTracks.FirstOrDefault().AddSink(_remoteView);
var theRemoteSurface = _remoteView.Holder.SurfaceFrame;
var metrics = Resources.System.DisplayMetrics;
// this is wrong and should be the remote video aspect ratio
decimal remoteRatio = decimal.Divide((theRemoteSurface.Right - theRemoteSurface.Left), (theRemoteSurface.Bottom - theRemoteSurface.Top));
decimal myRatio = decimal.Divide(metrics.WidthPixels, metrics.HeightPixels);
var audioTracks = p0.AudioTracks.OfType<AudioTrack>();
audioTracks.FirstOrDefault().SetEnabled(true);
audioTracks.FirstOrDefault().SetVolume(10);
}
catch (Exception ex)
{
}
}