我正在为Android应用程序开发一个webrtc。关于webrtc连接的一切都按预期工作,但是现在我给SurfaceViewRenderer
设置了动画,因此远程视频从填充整个屏幕过渡到右上角的小矩形,反之亦然(从小到大) 。
我正在使用MotionLayout
和MotionScene
来实现这一目标,其中SurfaceViewRenderer
带有几个定义SurfaceViewRenderer
属性的状态,这些属性会随着时间的变化而变化,从而获得良好而平滑的调整大小效果。 / p>
视图本身会随着时间的推移适当调整大小,但是动画播放期间视频会停止播放,因此,从小到大时,最后一个视频帧会保持很小,而视图会增大其大小。在动画结束时,当视频播放恢复时,将出现一个新的大视频帧并填充视图。因此,我得到的不是像从小到大的平滑调整大小效果,而是变得更像 skip 效果,在这里,小视频播放停止,然后在几毫秒后恢复播放并变大。
我尝试过的事情
VideoRenderer
,VideoTrack
,<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:orientation="vertical"
app:layoutDescription="@xml/motion_master_view_scene"
android:id="@+id/webRtcViewsLayout">
<org.webrtc.SurfaceViewRenderer
android:id="@+id/slaveVideoView"
android:layout_width="300dp"
android:layout_height="169dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="84dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<org.webrtc.SurfaceViewRenderer
android:id="@+id/masterVideoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.motion.MotionLayout>
),以找到一种方法来获取当前视频帧并调整其大小,但没有找到方法< / li>
复制步骤
要重现确切的场景将非常困难,因为您将需要与信令服务器一起设置一个webrtc环境,但是我将共享我正在使用的代码段。我的主要布局如下:
MotionScene
然后我的motion_master_view_scene.xml <?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:motion="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
motion:duration="500">
</Transition>
<StateSet
motion:defaultState="@id/localMasterState">
<State android:id="@+id/bothMinimizedState" motion:constraints="@id/bothMinimizedConstraintSet"></State>
<State android:id="@+id/localMasterState" motion:constraints="@id/localMasterConstraintSet"></State>
</StateSet>
<ConstraintSet android:id="@+id/bothMinimizedConstraintSet">
<Constraint
android:id="@+id/masterVideoView"
android:layout_width="300dp"
android:layout_height="169dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="196dp"
android:layout_marginRight="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<Constraint
android:id="@+id/slaveVideoView"
android:layout_width="300dp"
android:layout_height="169dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</ConstraintSet>
<ConstraintSet android:id="@+id/localMasterConstraintSet">
<Constraint
android:id="@+id/masterVideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Constraint
android:id="@+id/slaveVideoView"
android:layout_width="300dp"
android:layout_height="169dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</ConstraintSet>
</MotionScene>
看起来像这样:
webRtcViewsLayout.transitionToState(newState)
最后,我通过执行此操作在MainActivity中的状态之间进行更改
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator/com.example.calculator.MainActivity}: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3037)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #15: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:794)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7767)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7958)
at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1997)
at android.support.design.widget.AppBarLayout$LayoutParams.<init>(AppBarLayout.java:743)
at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:366)
at android.support.design.widget.AppBarLayout.generateLayoutParams(AppBarLayout.java:110)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at com.example.calculator.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:7149)
at android.app.Activity.performCreate(Activity.java:7140)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
有关如何解决这种情况的任何线索?