Android Question cctv cool + php +AUDIO rec&send +QUALITY IMAGES to Internet using PHP + b4a , fixes awesome!

xpectmore

Member
Licensed User
Longtime User
image.jpg index.jpg index.jpg image.jpg index.jpg
index.jpg
image.jpg
in case someone have erros on camera on cctv examples i hope this will fix your problem like in my case..
this example is based to all cctv Erel's examples and i was able to resolve the error i submit here https://www.b4x.com/android/forum/threads/camera-preview-memory-leak.73321/#post-485143
the fix was Camera example that use libraries Camera,Core,Phone,Reflection and the class CameraEx
as client.
as server i use xampp or external php+mysql hosting
how i said in the link above you must install in database test the table:
B4X:
CREATE TABLE `chezzeina_video` ( `id` INT NULL AUTO_INCREMENT , `pic` LONGBLOB NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

if you have xampp with password edit put.php and get.php and change the password you have.
the quick generate table is open localhost/phpmyadmin/ click on left on test then in the middle up to sql then paste that then push 'go'.

localhost is 127.0.0.1 so you must have the phone and the pc (or any other seccond device) in the same network(connected to the same router,or conected by bluetooth tethering and internet sharing, or wireless tethering with internet sharing or the last : wifi direct from pc with the pc connected by lan,wifi key adapter,.....any method).so go to pc to find out your ip ,basicly in windows 10 go to Network Connections (in my case i am connected via wireless) so click right over Wi-Fi ,status, detailes and see the ip4 address.
if you are advanced see ipconfig /all with the same results..
in my case my lan ip is 192.168.43.227 you can see it in client b4a 's source.
the php code had in index a style part what will rotate 90 degrees your image.

using this method i have no more errors ,no more green images no memory leaks like the guy report that in the link i provide in the header of this post.
Thanks to Erel for camera and cctv posts and i hope someone much advanced in java and b4a will discover how to arround that error to obtain more efficients.

if will not use as server these php files you can use the server of Erel's example one of them :
https://www.b4x.com/android/forum/pages/results/?query=cctv
my php version of server part had blinks because jquery methods to load frames have some delays from pic's time loading (the blink will be increased by internet speed too and the speed of downloading of the host where you put that =lan/external).



for external hosting you may set the mysql password in the way i said and to upload the files via ftp over your hosted php plan(that will allow you even you have restrictions cause this method reads from posts a frame and it's send it to mysql blob reccord , so is a very basic stuff ,common nothing special).

IN XAMPP CASE ON WINDOWS / LINUX UBUNTU OVER A PC I HOPE YOU UNDERSTAND WHAT IS MEAN ADD FIREWALL EXCEPTIONS FOR XAMPP.IF YOU DON'T KNOW THIS PART I SUGEST YOU GOOGLEIZE OR YOUTUBIZE A FIREWALL EXCEPTION TO SEE MORE..



====================================================
Update 1
====================================================

i know what was wrong with that cctv examples and why i got green images.
i check images stored in mysql i found the size is increase. so i put in main of b4a pasting from Erel's examples setpreviewsize parts and the sub in cameraex sub as well

B4X:
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.StartPreview
        camEx.SetJpegQuality(100)
        camEx.SetPreviewSize(640, 480)
        camEx.CommitParameters
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub


B4X:
Public Sub SetPreviewSize(Width As Int, Height As Int)
    r.target = parameters
    r.RunMethod3("setPreviewSize", Width, "java.lang.int", Height, "java.lang.int")
End Sub


mades these modifies will results again in green images.it's this the source of errors i have with other examples

...
...
TESTING ...
...
DONE ! DONE ! DONE ! DONE !

Sub Camera1_Ready (Success As Boolean)
If Success Then
camEx.StartPreview

'camEx.SetPreviewSize(640, 480)
'btnPictureSize_Click

camEx.SetPictureSize(640, 480)

ToastMessageShow(640 & "x" & 480, False)
' I THINK THIS IS WORKING LIKE A
' SMALL DELAY AND HAD MILISECCONDS TIME TO PUT
' THERE INFO BEFORE COMIT
camEx.CommitParameters


camEx.SetJpegQuality(100)
camEx.CommitParameters
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub




so the final is
put this part in main

B4X:
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.StartPreview
        camEx.SetPictureSize(640, 480)
        camEx.delay(100)
        camEx.SetJpegQuality(100)
        camEx.CommitParameters
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub

and in CameraExClass put this
B4X:
public Sub delay(lG_SleepEndMs As Long)
  Do While (DateTime.Now < lG_SleepEndMs)
  Loop
End Sub


thank you briaoh https://www.b4x.com/android/forum/threads/sleep-for-milliseconds.69984/#post-444262



====================================================
Update 2
====================================================


done ! no more image blinks !!!
modify index.php to
B4X:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="js/jquery.js" type="text/javascript"></script>
    <style>
#r90 {
/*General*/
transform: rotate(90deg);
/*Firefox*/
-moz-transform: rotate(90deg);
/*Microsoft Internet Explorer*/
-ms-transform: rotate(90deg);
/*Chrome, Safari*/
-webkit-transform: rotate(90deg);
/*Opera*/
-o-transform: rotate(90deg);
/*alter opacity*/
/*opacity:0.4;
filter:alpha(opacity=40);*/
margin-top:50px;
}
    </style>
</head>
<body>
    <h1></h1>
    <div id="images"><img id="r90" width="640px" height="480px" /></div>
    <script type="text/javascript">
    function get_images(){
        $.ajax({
           url: "get.php",
           success: function(result)
           {
               $('img#r90').attr('src','data:image/jpg;base64,'+result);
           },
         });
    }
    $(document).ready(function(){
        get_images();
        setInterval(function(){get_images();}, 200);
    });
    </script>
</body>




====================================================
Update 3
====================================================

the best results i got i uploaded on update3_all_b4a_cctv_plus+php.zip
i have no more errors,no blinkin images,i can set any resolution

thanks Erel and all who posting to help everybody





====================================================

Update 3 hot
====================================================


with
Update_4_Image_streaming_and_audio.zip
you can now streaming images and audio in the same time or not.
is like walkie talkie but video!

you may drop/update old table from the last update and run this new code in phpmyadmin
now are 2 tables first for images and the seccond you guess .. for audio small wavs..
B4X:
CREATE TABLE `chezzeina_video` ( `id` INT NULL AUTO_INCREMENT , `pic` LONGBLOB NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE `chezzeina_audio` ( `id` INT NULL AUTO_INCREMENT , `audio` longblob NOT NULL, `viewed` varchar(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) )  ENGINE = InnoDB;



i had troubles to redirect direct Audiostreamer to external audio player (because i had limited experience with b4a and cause is raw audio and i don't know how to apply wav header direct to a audiostreamer buffers() Byte . )




====================================================
Update 4 better
====================================================
quality images
register audio how much you want(you may experiment yourself the max lenght for audio)
the database will not be filled by a lot of content anymore(will delete old views)
the image you can put it anywhere on page see php part

all these modifies in Update4.zip
 

Attachments

  • php.zip
    30.1 KB · Views: 444
  • Camera.zip
    23 KB · Views: 401
  • update3_all_b4a_cctv_plus+php.zip
    64.3 KB · Views: 396
  • Update_4_Image_streaming_and_audio.zip
    55.7 KB · Views: 391
  • Update4.zip
    117.1 KB · Views: 476
Last edited:
Top