在Android中使用VideoView问题问题、Android、VideoView

2023-09-05 00:12:04 作者:怪我与你不合称

我使用VideoView在Android中显示流媒体视频。 在播放视频,如果用户接收和放大器;断开呼叫,视频开始的开始,而不是它应该是呼叫断开之后,该视频应该从收到呼叫时,在同一个地方玩的行为打。

I am using VideoView in Android for displaying streaming videos. While playing the videos if a user receives & disconnects the call , the video starts playing from beginning instead of the behaviour which should be that after the call disconnection , the video should start playing from the same place when the call was received.

请提供您的建议/样品code,如果你已经实现了相同的。

Kindly provide your suggestions/sample code if you have already implemented the same.

亲切问候,

CB

推荐答案

我没有尝试这样做,但是这就是我将开始:

I have not tried this, but this is where I would start:

步骤1:在的onStop(),呼叫 getCurrentPosition()的VideoView和保存价值。

Step #1: In onStop(), call getCurrentPosition() on the VideoView and save the value.

步骤2:在 ONSTART(),呼叫 getCurrentPosition() VideoView ,并将其与步骤#1的值。如果它们不同(例如, getCurrentPosition()现在 0 ),调用 seekTo() ,提供从步骤#值1。

Step #2: In onStart(), call getCurrentPosition() on the VideoView and compare it to the value from Step #1. If they differ (e.g., getCurrentPosition() is now 0), call seekTo(), supplying the value from Step #1.

第三步:在的onSaveInstanceState(),呼叫 getCurrentPosition() VideoView 和值存储在附送捆绑

Step #3: In onSaveInstanceState(), call getCurrentPosition() on the VideoView and store the value in the supplied Bundle.

第四步:在 onRestoreInstanceState(),获得第3步从价值提供的捆绑和把它放在使用步骤#1和步骤#2的数据成员。

Step #4: In onRestoreInstanceState(), obtain the value from Step #3 from the supplied Bundle and put it in the data member used by Step #1 and Step #2.

这应该包括你,而电话是怎么回事时可能发生的相关场景。

This should cover you for the relevant scenarios that might occur while the phone call is going on.