1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
6#define MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
7
8#include "base/basictypes.h"
9#include "base/containers/hash_tables.h"
10#include "base/strings/string_piece.h"
11#include "base/threading/non_thread_safe.h"
12#include "base/time/time.h"
13#include "media/base/media_export.h"
14
15namespace media {
16
17// This class is used for reproduction of system sounds. All methods
18// should be accessed from the Audio thread.
19class MEDIA_EXPORT SoundsManager : public base::NonThreadSafe {
20 public:
21  typedef int SoundKey;
22
23  // Creates a singleton instance of the SoundsManager.
24  static void Create();
25
26  // Removes a singleton instance of the SoundsManager.
27  static void Shutdown();
28
29  // Returns a pointer to a singleton instance of the SoundsManager.
30  static SoundsManager* Get();
31
32  // Initializes SoundsManager with the wav data for the system
33  // sounds. Returns true if SoundsManager was successfully
34  // initialized.
35  virtual bool Initialize(SoundKey key, const base::StringPiece& data) = 0;
36
37  // Plays sound identified by |key|, returns false if SoundsManager
38  // was not properly initialized.
39  virtual bool Play(SoundKey key) = 0;
40
41  // Returns duration of the sound identified by |key|. If SoundsManager
42  // was not properly initialized or |key| was not registered, this
43  // method returns an empty value.
44  virtual base::TimeDelta GetDuration(SoundKey key) = 0;
45
46 protected:
47  SoundsManager();
48  virtual ~SoundsManager();
49
50 private:
51  DISALLOW_COPY_AND_ASSIGN(SoundsManager);
52};
53
54}  // namespace media
55
56#endif  // MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
57