aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/util/SoundFileUtils.java
blob: e5adfa4b68c2f7c5134aab920e1c9efc3aeadf35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.util;

import java.io.*;

/**
 * Defines the different permit extension file.
 *
 * @author Alexandre Maillard
 * @author Dmitri Melnikov
 */
public class SoundFileUtils 
{
    /**
     * Different extension of a sound file
     */
    public final static String wav = "wav";
    public final static String mid = "midi";
    public final static String mp2 = "mp2";
    public final static String mp3 = "mp3";
    public final static String mod = "mod";
    public final static String ram = "ram";
    public final static String wma = "wma";
    public final static String ogg = "ogg";
    public final static String gsm = "gsm";
    public final static String aif = "aiff";
    public final static String au = "au";

    /**
     * The file extension and the format of call recording to be used by
     * default. 
     */
    public static final String DEFAULT_CALL_RECORDING_FORMAT = mp3;

    /**
     * Checks whether this file is a sound file.
     * 
     * @param f <tt>File</tt> to check
     * @return <tt>true</tt> if it's a sound file, <tt>false</tt> otherwise
     */
    public static boolean isSoundFile(File f)
    {
        String ext = getExtension(f);

        if (ext != null)
        {
            return
                ext.equals(wma)
                    || ext.equals(wav)
                    || ext.equals(ram)
                    || ext.equals(ogg)
                    || ext.equals(mp3)
                    || ext.equals(mp2)
                    || ext.equals(mod)
                    || ext.equals(mid)
                    || ext.equals(gsm)
                    || ext.equals(au);
        }
        return false;
    }

    /**
     * Gets the file extension.
     * TODO: There are at least 2 other methods like this scattered around
     * the SC code, we should move them all to util package.
     *
     * @param f which wants the extension
     * @return Return the extension as a String
     */  
    public static String getExtension(File f) 
    {
        String s = f.getName();
        int i = s.lastIndexOf('.');
        String ext = null;

        if ((i > 0) &&  (i < s.length() - 1))
            ext = s.substring(i+1).toLowerCase();
        return ext;
    }
}