I have been working on having videos stored in a DB. but I seem to be having a problem that is bottling me for some while.
I tried using Cagaty's example of streaming videos and it worked, but once I wish to extend this it falls apart.
On the video streaming example the pojo is static. As It can contain 1 video at a time. My extension was to have a container that would have several dynamically filled "video streaming examples", but when tested it doesnt return the video. I checked the mime-type returned, and its text/html and not the value set that is video/quicktime.
If i remove the carousel and just place A media and bind it to mediaStreamer class calling GetVideo() it workes, but its only one A video at a time...
Any suggestions would be appreciated.
here's the code:
Code: Select all
<p:carousel value="#{News.news}" var="headline" itemStyle="height:400px;width:600px" autoPlayInterval="2000" rows="1" effect="easeIn" circular="true" style="width:50%;margin:auto;">
<p:tab title="#{headline.fileName}">
<p:media style="z-index:-1" value="#{headline.media}" width="600" height="400" player="quicktime">
<f:param name="cache" value="true"/>
<f:param name="controller" value="true"/>
<f:param name="autoplay" value="false"/>
</p:media>
</p:tab>
</p:carousel>
Code: Select all
@ManagedBean(name = "News")
@SessionScoped
public class NewsMedia implements Serializable {
private ArrayList<MediaStreamer> _news;
public NewsMedia() {
_news = new ArrayList<MediaStreamer>();
//look in the DB for all the info.
Connection Con = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("portalgc");
Con = ds.getConnection();
String fetchSql = "select * from portalgc.media";
PreparedStatement ps = Con.prepareStatement(fetchSql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
_news.add(new MediaStreamer(rs.getString("MediaName"), rs.getString("MediaExtension"), rs.getString("MediaMimeType"), rs.getBinaryStream("MediaContent")));
}
rs.close();
ps.close();
Con.close();
} catch (Exception ex) {
Logger.getLogger(NewsMedia.class.getName()).log(Level.SEVERE, null, ex);
}
}
public ArrayList<MediaStreamer> getNews() {
return _news;
}
public void setNews(ArrayList<MediaStreamer> news) {
this._news = news;
}
}
Code: Select all
@ManagedBean(name = "MediaStreamer")
public class MediaStreamer {
private StreamedContent _media;
private String _fileName;
private String _fileExtension;
private String _MimeType;
public MediaStreamer() {
_media = null;
_fileName = "";
_fileExtension = "";
_MimeType = "video/quicktime";
}
public MediaStreamer(String fileName, String fileExtension, String MimeType, InputStream stream) {
_fileName = fileName;
_fileExtension = fileExtension;
_media = new DefaultStreamedContent(stream, "video/quicktime");
}
public StreamedContent GetVideo() {
InputStream stream = null;
Connection Con = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("portalgc");
Con = ds.getConnection();
String fetchSql = "select MediaContent from portalgc.media";
PreparedStatement ps = Con.prepareStatement(fetchSql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
stream = rs.getBinaryStream("MediaContent");
}
rs.close();
ps.close();
Con.close();
} catch (Exception ex) {
try {
Con.close();
} catch (SQLException ex1) {
Logger.getLogger(filearchive.class.getName()).log(Level.SEVERE, null, ex1);
}
}
if (stream != null) {
setMedia(new DefaultStreamedContent(stream, "video/quicktime"));
} else {
setMedia(null);
}
return getMedia();
}
//<editor-fold defaultstate="collapsed" desc="Properties">
public StreamedContent getMedia() {
return _media;
}
public void setMedia(StreamedContent media) {
this._media = media;
}
public String getFileName() {
return _fileName;
}
public void setFileName(String fileName) {
this._fileName = fileName;
}
public String getFileType() {
return _fileExtension;
}
public void setFileType(String fileType) {
this._fileExtension = fileType;
}
public String getMimeType() {
return _MimeType;
}
public void setMimeType(String MimeType) {
this._MimeType = MimeType;
} //</editor-fold>
}