Friday 11 August 2017

Create Thumbnail in Video in Spring and ffmpeg

import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.jcodec.api.FrameGrab; import org.jcodec.api.JCodecException; import org.jcodec.common.model.Picture; import org.jcodec.scale.AWTUtil; public class VideoThumbTaker { private String VIDEO_THUMBNAIL_FOLDER_NAME = "thumbnail"; private String UPLOAD_DIRECTORY = "D:/images/" protected String ffmpegApp; public VideoThumbTaker(String ffmpegApp) { this.ffmpegApp = ffmpegApp; } public static String captureImage(String inputFile, int organizationId) throws Exception, IOException, JCodecException { String filename = Constants.VIDEO_THUMBNAIL_FILE_PREFIX+System.currentTimeMillis()+".png"; int frameNumber = 1; Picture picture = FrameGrab.getFrameFromFile(new File(inputFile), frameNumber); BufferedImage bufferedImage = AWTUtil.toBufferedImage(picture); ImageIO.write(bufferedImage, "png", new File(UPLOAD_DIRECTORY+"/"+VIDEO_THUMBNAIL_FOLDER_NAME+"/" + filename)); return "o"+organizationId+"/"+VIDEO_THUMBNAIL_FOLDER_NAME+"/" + filename; } }

Send Google FCM Push Notification Using Spring Boot

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.esense.touch.dbconstants.NOTIFICATION; import com.esense.touch.dbconstants.STORY; import com.esense.touch.dbconstants.USER_NOTIFICATION; import com.esense.touch.dbconstants.USER_ROLE; import com.esense.touch.dbconstants.USER_ROLE_DETAIL; import com.esense.touch.service.NotificationService; @Service public class PushNotificationService { private String AUTH_KEY_FCM="your server auth key"; @Autowired NotificationService notificationService; public String sendPushNotification(Rows row) throws IOException { String result = ""; URL url = new URL(Constants.API_URL_FCM); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "key=" + AUTH_KEY_FCM); conn.setRequestProperty("Content-Type", "application/json"); try { JSONObject json = new JSONObject(); json.put("to", "device Id"); JSONObject info = new JSONObject(); String notificationTitle = "Notification"; info.put("title", notificationTitle); info.put("body", "Content"); info.put("image","abc/abc.jpg"); json.put("data", info); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(json.toString()); wr.flush(); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder sb = new StringBuilder(); String output; while ((output = br.readLine()) != null) { sb.append(output); } JSONObject outputobj = new JSONObject(sb.toString()); if(outputobj.get("success").equals(1)){ // success you can write your success code here } result = "success"; } catch (Exception e) { e.printStackTrace(); result = "failure"; } return result; } }

Thursday 25 May 2017

Context menu design using angularjs

File : app.js
var myApp = angular.module("myApp",[]);

myApp.controller( "MainCtrl", [ "$scope", function($scope) {
    console.log("Main Controller loaded.");
    $scope.myContextDiv = "
  • Item 1
  • Item 2
"; $scope.clickedItem1 = function(){ console.log("Clicked item 1."); }; $scope.clickedItem2 = function(){ console.log("Clicked item 2."); }; }]); myApp.directive( "contextMenu", function($compile){ contextMenu = {}; contextMenu.restrict = "AE"; contextMenu.link = function( lScope, lElem, lAttr ){ lElem.on("contextmenu", function (e) { e.preventDefault(); // default context menu is disabled // The customized context menu is defined in the main controller. To function the ng-click functions the, contextmenu HTML should be compiled. lElem.append( $compile( lScope[ lAttr.contextMenu ])(lScope) ); // The location of the context menu is defined on the click position and the click position is catched by the right click event. $("#contextmenu-node").css("left", e.clientX); $("#contextmenu-node").css("top", e.clientY); }); lElem.on("mouseleave", function(e){ console.log("Leaved the div"); // on mouse leave, the context menu is removed. if($("#contextmenu-node") ) $("#contextmenu-node").remove(); }); }; return contextMenu; });

File : index.html
Right Click On the Item!

File : style.html
#contextmenu-node{
    position: absolute;
    background-color: white;
    border: solid #CCCCCC 1px;
}

.contextmenu-item{
    margin: 0.5em;
    padding-left: 0.5em;
}

.contextmenu-item:hover{
    background-color: #CCCCCC;
    cursor: default;
}


Create Thumbnail in Video in Spring and ffmpeg

import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.jcodec.api.Fr...