1 package tim.prune.load;
5 import tim.prune.data.AudioFile;
6 import tim.prune.data.MediaFile;
7 import tim.prune.data.MediaList;
8 import tim.prune.data.Photo;
9 import tim.prune.data.Track;
12 * Class to provide helper functions for loading media
14 public abstract class MediaHelper
17 private static GenericFileFilter _jpegFilter = null, _audioFilter = null;
20 * Construct a MediaFile object for the given path
21 * @param inPath path to file
22 * @return either Photo or AudioFile object as appropriate, or null
24 public static MediaFile createMediaFile(String inPath)
26 if (inPath == null) {return null;}
27 File file = new File(inPath);
28 if (!file.exists() || !file.canRead() || !file.isFile()) {return null;}
29 // Initialise filters if necessary
30 if (_jpegFilter == null) {
31 _jpegFilter = new JpegFileFilter();
32 _audioFilter = new AudioFileFilter();
34 // Check if filename looks like a jpeg
35 if (_jpegFilter.acceptFilename(file.getName())) {
36 return JpegLoader.createPhoto(file);
38 // Check if filename looks like an audio file
39 if (_audioFilter.acceptFilename(file.getName())) {
40 return new AudioFile(file);
42 // Neither photo nor audio
47 * Add all the media from the given track into the specified list
48 * @param inTrack track from which media to take
49 * @param inMediaList list to which media should be added
50 * @param inMediaClass class of media, either Photo or AudioFile
52 public static void addMediaFromTrack(Track inTrack, MediaList inMediaList,
53 Class<?> inMediaClass)
55 final int numPoints = inTrack.getNumPoints();
56 for (int i=0; i<numPoints; i++)
58 MediaFile media = null;
59 if (inMediaClass == Photo.class) {
60 media = inTrack.getPoint(i).getPhoto();
62 else if (inMediaClass == AudioFile.class) {
63 media = inTrack.getPoint(i).getAudio();
66 inMediaList.addMedia(media);