19 package org.sleuthkit.autopsy.contentviewers;
21 import java.awt.CardLayout;
22 import java.awt.Component;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
26 import org.freedesktop.gstreamer.GstException;
27 import org.openide.util.NbBundle;
35 @SuppressWarnings(
"PMD.SingularField")
36 class MediaFileViewer extends javax.swing.JPanel implements FileTypeViewer {
38 private static final Logger LOGGER = Logger.getLogger(MediaFileViewer.class.getName());
39 private static final long serialVersionUID = 1L;
40 private AbstractFile lastFile;
42 private MediaPlayerPanel mediaPlayerPanel;
43 private final MediaViewImagePanel imagePanel;
44 private final boolean imagePanelInited;
46 private static final String IMAGE_VIEWER_LAYER =
"IMAGE";
47 private static final String MEDIA_PLAYER_LAYER =
"AUDIO_VIDEO";
57 mediaPlayerPanel =
new MediaPlayerPanel();
58 }
catch (GstException | UnsatisfiedLinkError ex) {
59 LOGGER.log(Level.SEVERE,
"Error initializing gstreamer for audio/video viewing and frame extraction capabilities", ex);
60 MessageNotifyUtil.Notify.error(
61 NbBundle.getMessage(
this.getClass(),
"MediaFileViewer.initGst.gstException.msg"),
64 imagePanel =
new MediaViewImagePanel();
65 imagePanelInited = imagePanel.isInited();
67 customizeComponents();
68 LOGGER.log(Level.INFO,
"Created MediaView instance: {0}",
this);
71 private void customizeComponents() {
72 add(imagePanel, IMAGE_VIEWER_LAYER);
74 if (mediaPlayerPanel != null) {
75 add(mediaPlayerPanel, MEDIA_PLAYER_LAYER);
86 @SuppressWarnings(
"unchecked")
88 private
void initComponents() {
90 setLayout(
new java.awt.CardLayout());
91 getAccessibleContext().setAccessibleDescription(
org.openide.util.NbBundle.getMessage(MediaFileViewer.class,
"MediaFileViewer.AccessibleContext.accessibleDescription"));
102 public List<String> getSupportedMIMETypes() {
104 List<String> mimeTypes =
new ArrayList<>();
106 mimeTypes.addAll(this.imagePanel.getSupportedMimeTypes());
107 if (mediaPlayerPanel != null) {
108 mimeTypes.addAll(this.mediaPlayerPanel.getSupportedMimeTypes());
120 public void setFile(AbstractFile file) {
128 if (file.equals(lastFile)) {
133 if (mediaPlayerPanel != null && mediaPlayerPanel.isSupported(file)) {
134 mediaPlayerPanel.loadFile(file);
135 this.showVideoPanel();
136 }
else if (imagePanelInited && imagePanel.isSupported(file)) {
137 imagePanel.loadFile(file);
138 this.showImagePanel();
140 }
catch (Exception e) {
141 LOGGER.log(Level.SEVERE,
"Exception while setting node", e);
148 private void showVideoPanel() {
149 CardLayout layout = (CardLayout) this.getLayout();
150 layout.show(
this, MEDIA_PLAYER_LAYER);
156 private void showImagePanel() {
157 CardLayout layout = (CardLayout) this.getLayout();
158 layout.show(
this, IMAGE_VIEWER_LAYER);
162 public Component getComponent() {
167 public void resetComponent() {
168 if (mediaPlayerPanel != null) {
169 mediaPlayerPanel.reset();
183 List<String> getSupportedMimeTypes();
190 List<String> getSupportedExtensions();
192 boolean isSupported(AbstractFile file);
196 public boolean isSupported(AbstractFile file){
197 return mediaPlayerPanel.isSupported(file) || imagePanel.isSupported(file);