com.neave.media.NeaveCamera modification


/ Published in: ActionScript 3
Save to your folder(s)

I modified the getCamera() function of the source available on http://www.neave.com/webcam/ so that if Camera.names is 0, the function does not create a camera


Copy this code and paste it in your HTML
  1. /**
  2.  * Neave Camera
  3.  *
  4.  * Copyright (C) 2008 Paul Neave
  5.  * http://www.neave.com/
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation at http://www.gnu.org/licenses/gpl.html
  10.  */
  11.  
  12. package com.neave.media
  13. {
  14. import flash.events.*;
  15. import flash.media.*;
  16. import flash.system.*;
  17.  
  18. public class NeaveCamera
  19. {
  20. /**
  21. * The requested width of the camera object
  22. */
  23. static public var CAMERA_WIDTH:int = 320;
  24.  
  25. /**
  26. * The requested height of the camera object
  27. */
  28. static public var CAMERA_HEIGHT:int = 240;
  29.  
  30. static private var cam:Camera;
  31.  
  32.  
  33. public function NeaveCamera()
  34. {
  35. }
  36.  
  37.  
  38. /**
  39. * Sets up and returns the camera object
  40. *
  41. * @return A camera object
  42. */
  43. static public function getCamera():Camera
  44. {
  45. // Return the same camera if it has been successfully requested before
  46. if(cam != null)
  47. {
  48. if(cam.muted)
  49. Security.showSettings(SecurityPanel.PRIVACY);
  50. return cam;
  51. }
  52.  
  53. // Get the camera
  54. cam = Camera.getCamera();
  55. if(cam != null)
  56. {
  57. // Set properties if a camera was found
  58. cam.setMode(CAMERA_WIDTH, CAMERA_HEIGHT, 30, true);
  59. cam.addEventListener(StatusEvent.STATUS, NeaveCamera.statusListener);
  60. return cam;
  61. }
  62. else
  63. {
  64. // No camera found
  65. if(Camera.names.length > 0)
  66. {
  67. // If there are cameras listed on the computer
  68. Security.showSettings(SecurityPanel.CAMERA);
  69. return new Camera();
  70. }
  71. else
  72. {
  73. // If there no cameras at all
  74. return null;
  75. }
  76. }
  77. }
  78.  
  79.  
  80. /**
  81. * Whether the camera object is available or not
  82. */
  83. static public function get muted():Boolean
  84. {
  85. return cam == null || cam.muted || cam.name == null || cam.width == 0;
  86. }
  87.  
  88.  
  89. /**
  90. * Camera status response
  91. */
  92. static private function statusListener(e:StatusEvent):void
  93. {
  94. switch(e.code)
  95. {
  96. case "Camera.Unmuted":
  97. Security.showSettings(SecurityPanel.CAMERA);
  98. break;
  99.  
  100. default:
  101. // trace(e.code);
  102. break;
  103. }
  104. }
  105. }
  106. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.