/flowplayer/trunk/src/actionscript/org/flowplayer/controller/LocalSOVolumeStorage.as

http://flowplayer-core.googlecode.com/ · ActionScript · 83 lines · 51 code · 11 blank · 21 comment · 8 complexity · aed6b7720d156e630ce51dd207f1e0e1 MD5 · raw file

  1. /*
  2. * Copyright 2008 Anssi Piirainen
  3. *
  4. * This file is part of FlowPlayer.
  5. *
  6. * FlowPlayer is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * FlowPlayer is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with FlowPlayer. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package org.flowplayer.controller {
  20. import org.flowplayer.util.Log;
  21. import org.flowplayer.controller.VolumeStorage;
  22. import flash.net.SharedObject;
  23. /**
  24. * @author api
  25. */
  26. internal class LocalSOVolumeStorage implements VolumeStorage {
  27. private var _storedVolume:SharedObject;
  28. private var log:Log = new Log(this);
  29. public function LocalSOVolumeStorage(storedVolume:SharedObject) {
  30. log.debug("in constructor");
  31. _storedVolume = storedVolume;
  32. }
  33. public static function create():VolumeStorage {
  34. try {
  35. return new LocalSOVolumeStorage(SharedObject.getLocal("org.flowplayer"));
  36. } catch (e:Error) {
  37. return new NullVolumeStorage();
  38. }
  39. return null;
  40. }
  41. public function persist():void {
  42. log.debug("persisting volume " + _storedVolume.data.volume);
  43. try {
  44. _storedVolume.flush();
  45. } catch (e:Error) {
  46. log.error("unable to persist volume");
  47. }
  48. }
  49. public function get volume():Number {
  50. log.debug("get volume " + _storedVolume.data.volume);
  51. if (_storedVolume.size == 0) return 0.5;
  52. return getVolume(_storedVolume.data.volume);
  53. }
  54. public function get muted():Boolean {
  55. return _storedVolume.data.volumeMuted;
  56. }
  57. public function set volume(value:Number):void {
  58. _storedVolume.data.volume = value;
  59. }
  60. public function set muted(value:Boolean):void {
  61. _storedVolume.data.volumeMuted = value;
  62. }
  63. private function getVolume(volumeObj:Object):Number {
  64. if (volumeObj == 0) return 0;
  65. if (!volumeObj is Number) return 0.5;
  66. if (isNaN(volumeObj as Number)) return 0.5;
  67. if (volumeObj as Number > 1) return 1;
  68. if (volumeObj as Number < 0) return 0;
  69. return volumeObj as Number;
  70. }
  71. }
  72. }