如何在Android视频视图中添加cookie(Header)以支持旧版本的android atleast直到软糖

时间:2021-03-30 18:24:40

I have a activity which have VideoView to play the videos.

我有一个活动,有VideoView播放视频。

I was simply setting uri to videoview like below.

我只是将uri设置为视频,如下所示。

 videoView.setVideoURI(videoUri); 

After some searching i found the below alternative which can take header values

经过一番搜索,我找到了下面的替代方案,它可以采用标题值

videoView.setVideoURI(videoUri,headers); 

Here headers is HashMap which has cookies added.

这里的标题是添加了cookie的HashMap。

But As mentioned in this url http://developer.android.com/reference/android/widget/VideoView.html#setVideoURI(android.net.Uri, java.util.Map)

但正如本网址中提到的http://developer.android.com/reference/android/widget/VideoView.html#setVideoURI(android.net.Uri,java.util.Map)

this new method is added in api 21 as it wont support in older versions. Is there any way to support this feature in older versions. Kindly help.

这个新方法在api 21中添加,因为它在旧版本中不支持。有没有办法在旧版本中支持此功能。请帮助。

Need for this is basically i need to send some session cookies to videoview which needed to play the video.

需要这个基本上我需要发送一些会话cookie到videoview播放视频。

Kindly note this is my first question in *. Please let me know if you need any information to get more idea on this issue.

请注意,这是我在*中的第一个问题。如果您需要任何信息以便更多地了解此问题,请与我们联系。

1 个解决方案

#1


-1  

Im not sure but i would suggest something like this:

我不确定,但我会建议这样的事情:

    CookieSyncManager.createInstance(videoView.getContext());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.setCookie(videoDomainURL, cookie_value);
    CookieSyncManager.getInstance().sync();
    videoView.setVideoURI(videoUri);

#1


-1  

Im not sure but i would suggest something like this:

我不确定,但我会建议这样的事情:

    CookieSyncManager.createInstance(videoView.getContext());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.setCookie(videoDomainURL, cookie_value);
    CookieSyncManager.getInstance().sync();
    videoView.setVideoURI(videoUri);