Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. var tabGroup = Titanium.UI.createTabGroup();
  2. var win = Titanium.UI.createWindow({
  3. title: "Video Recorder",
  4. backgroundColor: 'black'
  5. });
  6. var b = Titanium.UI.createButton({
  7. title:'Record Movie',
  8. width:200,
  9. height:40,
  10. top:20
  11. });
  12.  
  13. var tab = Titanium.UI.createTab({
  14. title:'video Recorder',
  15. window:win
  16. });
  17.  
  18. b.addEventListener('click', function()
  19. {
  20. if (b.title == 'Play Movie')
  21. {
  22. Titanium.API.info('path = '+movieFile.nativePath);
  23. var activeMovie = Titanium.Media.createVideoPlayer({
  24. backgroundColor:'#111',
  25. movieControlMode:Titanium.Media.VIDEO_CONTROL_DEFAULT,
  26. scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
  27. //contentURL:movieFile.nativePath
  28. media:movieFile.nativePath // note you can use either contentURL to nativePath or the file object
  29. });
  30. activeMovie.play();
  31.  
  32. activeMovie.addEventListener('complete', function()
  33. {
  34. movieFile.deleteFile();
  35. b.title = 'Record Movie';
  36. });
  37.  
  38. if (parseFloat(Titanium.Platform.version) >= 3.2)
  39. {
  40. win.add(activeMovie);
  41. }
  42. }
  43. else
  44. {
  45. Titanium.Media.showCamera({
  46.  
  47. success:function(event)
  48. {
  49. var video = event.media;
  50. movieFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mymovie.mov');
  51. movieFile.write(video);
  52. b.title = 'Play Movie';
  53. },
  54. cancel:function()
  55. {
  56.  
  57. },
  58. error:function(error)
  59. {
  60. // create alert
  61. var a = Titanium.UI.createAlertDialog({title:'Video'});
  62.  
  63. // set message
  64. if (error.code == Titanium.Media.NO_VIDEO)
  65. {
  66. a.setMessage('Device does not have video recording capabilities');
  67. }
  68. else
  69. {
  70. a.setMessage('Unexpected error: ' + error.code);
  71. }
  72.  
  73. // show alert
  74. a.show();
  75. },
  76. mediaTypes: Titanium.Media.MEDIA_TYPE_VIDEO,
  77. videoMaximumDuration:10000,
  78. videoQuality:Titanium.Media.QUALITY_HIGH
  79. });
  80.  
  81. }
  82.  
  83. });
  84.  
  85. win.add(b);
  86. tabGroup.addTab(tab);
  87. tabGroup.open();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement