Instantiation<?php
# Include the Echove SDK
require('echove.php');
# Instantiate the class, passing it our Brightcove API tokens
$bc = new Echove(
'z9Jp-c3-KhWc4fqNf1JWz6SkLDlbO0m8UAwOjDBUSt0.',
'z9Jp-c3-KhUSoOh0IV8SA6ghleZlti6W9mmC_IhdCnybDfHqhmloA..'
);
?>
Properties<?php
# Turn on HTTPS mode
$bc->__set('secure', TRUE);
# Make our API call
$videos = $bc->find('allVideos');
# Determine how many possible results there are
echo 'Total Videos: ' . $bc->total_count . '<br />';
# Make our API call
$videos = $bc->findAll();
# Determine how many times we called the Brightcove API
echo 'API Calls: ' . $bc->__get('api_calls');
?>
Error Handling<?php
# Create a try/catch
try {
# Make our API call
$video = $bc->find('find_video_by_id', 8604819001);
} catch(Exception $error) {
# Handle our error
echo $error;
die();
}
?>
Find Query<?php
# Make our API call
$video = $bc->find('find_video_by_id', 8604819001);
# Print the video name and ID
echo $video->name . ' (' . $video->id . ')';
?>
Find Query - Shorthand<?php
# Make our API call
$video = $bc->find('videoById', 8604819001);
?>
Find Query - Additional Parameters<?php
# Define our parameters
$params = array(
'id' => 8604819001,
'video_fields' => 'id,name,shortDescription'
);
# Make our API call
$video = $bc->find('videoById', $params);
?>
Find Query - True Find All<?php
# Define our parameters
$params = array(
'video_fields' => 'id,name'
);
# Make our API call
$videos = $bc->findAll('video', $params);
?>
Create - Video<?php
# Create an array of meta data from our form fields
$metaData = array(
'name' => $_POST['videoName'],
'shortDescription' => $_POST['videoShortDescription']
);
# Move the file out of 'tmp', or rename
rename($_FILES['videoFile']['tmp_name'], '/tmp/' . $_FILES['videoFile']['name']);
$file = '/tmp/' . $_FILES['videoFile']['name'];
# Upload the video and save the video ID
$id = $bc->createMedia('video', $file, $metaData);
?>
Create - Image<?php
# Create an array of meta data from our form fields
$metaData = array(
'type' => 'VIDEO_STILL',
'displayName' => $_POST['imageName']
);
# Move the file out of 'tmp', or rename
rename($_FILES['bcImage']['tmp_name'], '/tmp/' . $_FILES['bcImage']['name']);
$file = '/tmp/' . $_FILES['bcImage']['name'];
# Upload the image, assign to a video, and save the image asset ID
$id = $bc->createImage('video', $file, $metaData, 8604819001);
?>
Create - Playlist<?php
# Take a comma-separated string of video IDs and explode into an array
$videoIds = explode(',', $_POST['playlistVideoIds']);
# Create an array of meta data from our form fields
$metaData = array(
'name' => $_POST['playlistName'],
'shortDescription' => $_POST['playlistShortDescription'],
'videoIds' => $videoIds,
'playlistType' => 'explicit'
);
# Create the playlist and save the playlist ID
$id = $bc->createPlaylist('video', $metaData);
?>
Update - Video / Playlist<?php
# Create an array of the new meta data
$metaData = array(
'id' => 8604819001,
'shortDescription' => 'Our new short description.'
);
# Update a video with the new meta data
$bc->update('video', $metaData);
?>
Delete - Video / Playlist<?php
# Delete a 'video' by ID, and cascade the deletion
$bc->delete('video', 8604819001, NULL, TRUE);
?>
Status - Video Upload<?php
# Retrieve upload status
$status = $bc->getStatus('video', 8604819001);
?>
Share Video<?php
# List the accounts to share the video with
$ids = array(
123456789
);
# Share the videos, and save the new video IDs
$new_ids = $bc->shareMedia('video', 8604819001, $ids);
?>
Add To / Remove From Playlist<?php # Add two videos to a playlist $bc->addToPlaylist(44969780001, array(45061414001, 45062831001)); # Remove a video from a playlist $bc->removeFromPlaylist(44969780001, 45062831001); ?>
Convenience Methods - SEF URLs / Time Formatting<?php
# Make our API call
$video = $bc->find('videoById', 8604819001);
# Print the SEF video name and formatted duration
echo 'Name: ' . $bc->sef($video->name) . '<br />';
echo 'Duration:' . $bc->time($video->length) . '<br />';
?>
Convenience Methods - Automatic Timestamp Conversion<?php
# Set timestamp to 7 days ago (in seconds)
$time = time() - 604800;
# Make our API call
$videos = $bc->find('modifiedVideos', $time);
# Set timestamp to 7 days ago (in minutes)
$time = floor((time() - 604800) / 60);
# Make our API call
$videos = $bc->find('modifiedVideos', $time);
?>
Convenience Methods - Tags<?php
# Make our API call
$video = $bc->find('videoById', 8604819001);
# Parse any key=value tags into array
$video->tags = $bc->tags($video->tags);
# Print out each tag
foreach($video->tags as $key => $value)
{
echo $key . ': ' . $value . '<br />';
}
?>
Convenience Methods - Tag Filter<?php
# Make our API call
$videos = $bc->find('allVideos');
# Remove all videos without specified tags
$videos = $bc->filter($videos, 'published=true,include=true');
?>
Embed Player - Simple<script language="JavaScript" type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>
<?php
# Set our parameters
$params = array(
'width' => 312,
'height' => 567
);
# Print the embed code
echo $bc->embed('video', 10506233001, 10508262001, $params);
?>
Embed Player - Advanced<script language="JavaScript" type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>
<?php
# Set our parameters
$params = array(
'width' => 312,
'height' => 567
);
# Set additional parameters
$additional = array(
'@videoPlayer' => 'ref:myVid12345',
'wmode' => 'transparent'
);
# Print the embed code
echo $bc->embed('video', 10506233001, NULL, $params, $additional);
?>Copyright 2009 Matthew Congrove, Brian Franklin. Echove is not officially supported by Brightcove.
Echove License:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. YOU AGREE TO RETAIN IN THE SOFTWARE AND ANY MODIFICATIONS TO THE SOFTWARE THE REFERENCE URL INFORMATION, AUTHOR ATTRIBUTION AND CONTRIBUTOR ATTRIBUTION PROVIDED HEREIN.