Example #1
0
function createVideoIcon($file)
{
    /* should install ffmpeg for the method to work successfully  */
    if (checkFFMPEG()) {
        //generate thumbnail
        $preview = sys_get_temp_dir() . '/' . md5($file) . '.jpg';
        @unlink($preview);
        //capture video preview
        $command = "ffmpeg -i \"" . $file . "\" -f mjpeg -ss 00:00:01 -vframes 1 \"" . $preview . "\"";
        exec($command);
        return createIconGD($preview);
    } else {
        return base64_decode(videoThumbnail());
    }
}
Example #2
0
 /**
  * Process media upload response
  *
  * @param ProtocolNode $node
  *  Message node
  * @return bool
  */
 protected function processUploadResponse($node)
 {
     $id = $node->getAttribute("id");
     $messageNode = @$this->mediaQueue[$id];
     if ($messageNode == null) {
         //message not found, can't send!
         $this->eventManager()->fire("onMediaUploadFailed", array($this->phoneNumber, $id, $node, $messageNode, "Message node not found in queue"));
         return false;
     }
     $duplicate = $node->getChild("duplicate");
     if ($duplicate != null) {
         //file already on whatsapp servers
         $url = $duplicate->getAttribute("url");
         $filesize = $duplicate->getAttribute("size");
         //            $mimetype = $duplicate->getAttribute("mimetype");
         //            $filehash = $duplicate->getAttribute("filehash");
         $filetype = $duplicate->getAttribute("type");
         //            $width = $duplicate->getAttribute("width");
         //            $height = $duplicate->getAttribute("height");
         $filename = array_pop(explode("/", $url));
     } else {
         //upload new file
         $json = WhatsMediaUploader::pushFile($node, $messageNode, $this->mediaFileInfo, $this->phoneNumber);
         if (!$json) {
             //failed upload
             $this->eventManager()->fire("onMediaUploadFailed", array($this->phoneNumber, $id, $node, $messageNode, "Failed to push file to server"));
             return false;
         }
         $url = $json->url;
         $filesize = $json->size;
         //            $mimetype = $json->mimetype;
         //            $filehash = $json->filehash;
         $filetype = $json->type;
         //            $width = $json->width;
         //            $height = $json->height;
         $filename = $json->name;
     }
     $mediaAttribs = array();
     $mediaAttribs["xmlns"] = "urn:xmpp:whatsapp:mms";
     $mediaAttribs["type"] = $filetype;
     $mediaAttribs["url"] = $url;
     $mediaAttribs["file"] = $filename;
     $mediaAttribs["size"] = $filesize;
     $filepath = $this->mediaQueue[$id]['filePath'];
     $to = $this->mediaQueue[$id]['to'];
     switch ($filetype) {
         case "image":
             $icon = createIcon($filepath);
             break;
         case "video":
             $icon = videoThumbnail();
             break;
         default:
             $icon = '';
             break;
     }
     $mediaNode = new ProtocolNode("media", $mediaAttribs, null, $icon);
     if (is_array($to)) {
         $this->sendBroadcast($to, $mediaNode);
     } else {
         $this->sendMessageNode($to, $mediaNode);
     }
     $this->eventManager()->fire("onMediaMessageSent", array($this->phoneNumber, $to, $id, $filetype, $url, $filename, $filesize, $icon));
     return true;
 }