Links

   Quran Explorer - Interactive Audio Recitations & Translations
Showing posts with label multimedia. Show all posts
Showing posts with label multimedia. Show all posts

Tuesday, January 7, 2014

Primefaces GraphicImage from the datatabase

Hello

Need to use p:graphic image with data from the db?
here is your solution.....


XHTML

<p:graphicImage value="#{imageBean.getImg(148)}" alt="Logo" width="230" height="180"/>

ImageBean (getImg() method only)
NB: inspired by this discussion on LinkedIn

public DefaultStreamedContent getImg(int _id){

        try{

        img = IOService.getImage(getDs(),_id); //added this line only

        FacesContext context = FacesContext.getCurrentInstance();
        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            return new DefaultStreamedContent();
            }
        else{
            if (img == null){
            return new DefaultStreamedContent();
            }
            else{           
            return new DefaultStreamedContent(new ByteArrayInputStream(img),  "image/png");           
            }
         }
        }
       
      catch(Exception e){
        return new DefaultStreamedContent();
        }
      }


IOService (heavy lifting done by the getImage() method)

public static byte[] getImage(DataSource d, int _id){
          Connection con = null;
          byte[] imgBytes = null;
           try{
               con = d.getConnection();
               con.setAutoCommit(false);
               PreparedStatement ps = con.prepareStatement("SELECT memberphoto FROM members WHERE memberid = ? limit 1"); //change the SQL here...
               ps.setInt(1, _id);
               ResultSet rs = ps.executeQuery();
               while (rs.next()) {
               imgBytes = rs.getBytes(1);
               // use the data in some way here
               }
               rs.close();
               ps.close();
              con.setAutoCommit(true);
               }
          catch(SQLException ex){
               imgBytes = null;
              }
          catch(ClassCastException exx){
               imgBytes = null;
               }
           finally{
              
               return imgBytes;
               }
        }


Dont thank me for this......

==============
Footprint:
Primefaces 3.3.1
PostgreSQL 9.0.8
Tomcat7

Monday, January 24, 2011

FFMPEG - Multimedia Tool

FFmpeg is a free software/open source project that produces libraries and programs for handling multimedia data. It ships with Fedora Linux so I naturally took a dive and have never turned back.....

I normaly use it to convert multimedia files from one format to another. Being a command line tool u expect faster execution.

For example
Convert from MP4 to AVI

#ffmpeg -i inputfile.mp4 outfile.avi


To See Supported File Formats
#ffmpeg -formats

You will get output similar to this
FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration:
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
built on Nov 20 2009 15:52:49, gcc: 4.3.2 20081105 (Red Hat 4.3.2-7)
File formats:
E 3g2 3GP2 format
E 3gp 3GP format
DEA wmav1 Windows Media Audio 1
DEA wmav2 Windows Media Audio 2
DEVSD wmv1 Windows Media Video 7
DEVSD wmv2 Windows Media Video 8
D V wmv3 Windows Media Video 9
DES dvbsub DVB subtitles
DES dvdsub DVD subtitles
DEV D dvvideo DV (Digital Video)
D V dxa Feeble Files/ScummVM DXA
D V D eacmv Electronic Arts CMV video
D V D eatgq Electronic Arts TGQ video
D V eatgv Electronic Arts TGV video
D V D eatqi Electronic Arts TQI Video
D V D escape124 Escape 124
.........To mention but a few