我正在使用vaadin视频在我的应用程序中集成一些视频。 这些视频在网络上受密码保护。我正在使用以下方法,但它不适合我。它一直在问我用户名和密码。
URL url = new URL(Constants.VIDEO_HTTP_ADDRESS + fileName + ".mp4");
URLConnection uc = url.openConnection();
String userpass = Constants.VIDEO_HTTP_ADDRESS_USERNAME + ":" + Constants.VIDEO_HTTP_ADDRESS_PASSWORD;
String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
uc.setRequestProperty("Authorization", basicAuth);
....
....
final Video v = new Video(label);
ExternalResource fileResource;
fileResource = new ExternalResource(url);
v.setSources(fileResource);
我有用户名和密码,我想在我的应用程序中集成这些视频,以便他们不需要明确的用户名和密码。
答案 0 :(得分:1)
正如@ f1sh在评论中指出的那样,您需要使用URLConnection
来获取视频资源。您可以使用ExternalResource
代替StreamResource
,而InputStream
允许从提供的Video v = new Video();
v.setSource(new StreamResource(new StreamSource() {
@Override
public InputStream getStream() {
try {
URL url = new URL(Constants.VIDEO_HTTP_ADDRESS + fileName + ".mp4");
URLConnection uc = url.openConnection();
String userpass = Constants.VIDEO_HTTP_ADDRESS_USERNAME + ":" + Constants.VIDEO_HTTP_ADDRESS_PASSWORD;
String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
uc.setRequestProperty("Authorization", basicAuth);
return uc.getInputStream();
} catch (IOException e) {
//add some exception handling here
}
}
}, fileName + ".mp4"));
加载资源。
这样的事情应该有效:
* {
margin: 0;
padding: 0;
}
figure {
position: absolute;
overflow: hidden;
cursor: pointer;
}
figcaption {
position: relative;
top: 30px;
background: rgba(230, 150, 15, 0.6);
transition: top 1s ease;
-moz-transition: top 1s ease;
-webkit-transition: top 1s ease;
-ms-transition: top 1s ease;
-o-transition: top 1s ease;
padding: 10px;
}
figure:hover figcaption {
top: -43px;
}
h1,
p {
color: #ffffff;
}