Documentation

MediaObject extends AbstractBaseApi

MediaObject API

Provides functionality for managing media objects and their tracks in Canvas LMS

Table of Contents

Properties

$canAddCaptions  : bool|null
Whether the current user can upload media_tracks (subtitles) to this Media Object
$mediaId  : string|null
The unique identifier for the media object
$mediaSources  : array<string|int, MediaSource>|null
Array of MediaSource objects with different encodings
$mediaTracks  : array<string|int, MediaTrack>|null
Array of MediaTrack objects associated with this media
$mediaType  : string|null
The type of media (video, audio)
$title  : string|null
The display title of the media object
$userEnteredTitle  : string|null
Custom title entered by the user
$apiClient  : HttpClientInterface
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Constructor
all()  : array<string|int, static>
Get all pages of results
fetchAttachments()  : array<string|int, MediaObject>
Fetch all media attachments (global context)
fetchAttachmentsByCourse()  : array<string|int, MediaObject>
Fetch media attachments for a specific course
fetchAttachmentsByGroup()  : array<string|int, MediaObject>
Fetch media attachments for a specific group
fetchByCourse()  : array<string|int, MediaObject>
Fetch media objects for a specific course
fetchByGroup()  : array<string|int, MediaObject>
Fetch media objects for a specific group
find()  : self
Find a specific media object by ID Note: Canvas API doesn't support direct media object retrieval
get()  : array<string|int, MediaObject>
Fetch all media objects (global context)
getTracks()  : array<string|int, MediaTrack>
Get media tracks for this media object
getTracksByAttachment()  : array<string|int, MediaTrack>
Get media tracks by attachment ID
paginate()  : PaginationResult
Get paginated results with metadata
setApiClient()  : void
Set the API client
toArray()  : array<string, mixed>
Convert the MediaObject to an array
update()  : self
Update the media object
updateByAttachment()  : self
Update the media object by attachment ID
updateTracks()  : array<string|int, MediaTrack>
Update media tracks for this media object
updateTracksByAttachment()  : array<string|int, MediaTrack>
Update media tracks by attachment ID
castValue()  : DateTime|mixed
Cast a value to the correct type
checkApiClient()  : void
Check if the API client is set, if not, instantiate a new one
convertPaginatedResponseToModels()  : array<string|int, static>
Helper method to convert paginated response data to model instances
createConfiguredHttpClient()  : HttpClient
Create an HttpClient with configured middleware
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
getEndpoint()  : string
Get the endpoint for this API resource MediaObjects don't have a single endpoint, so this throws an exception
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data
toDtoArray()  : array<string|int, mixed>
Convert the object to an array

Properties

$canAddCaptions

Whether the current user can upload media_tracks (subtitles) to this Media Object

public bool|null $canAddCaptions = null

$mediaId

The unique identifier for the media object

public string|null $mediaId = null

$mediaSources

Array of MediaSource objects with different encodings

public array<string|int, MediaSource>|null $mediaSources = null

$mediaTracks

Array of MediaTrack objects associated with this media

public array<string|int, MediaTrack>|null $mediaTracks = null

$mediaType

The type of media (video, audio)

public string|null $mediaType = null

$title

The display title of the media object

public string|null $title = null

$userEnteredTitle

Custom title entered by the user

public string|null $userEnteredTitle = null

$methodAliases

Define method aliases

protected static array<string|int, mixed> $methodAliases = ['get' => ['fetch', 'list', 'fetchAll'], 'all' => ['fetchAllPages', 'getAll'], 'paginate' => ['getPaginated', 'withPagination', 'fetchPage'], 'find' => ['one', 'getOne']]

Methods

__callStatic()

Magic method to handle function aliases

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>
Tags
throws
InvalidArgumentException

__construct()

Constructor

public __construct([array<string, mixed> $data = [] ]) : mixed
Parameters
$data : array<string, mixed> = []

all()

Get all pages of results

public static all([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
array<string|int, static>

fetchAttachments()

Fetch all media attachments (global context)

public static fetchAttachments([array<string, mixed> $params = [] ]) : array<string|int, MediaObject>
Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, MediaObject>

Array of MediaObject instances

fetchAttachmentsByCourse()

Fetch media attachments for a specific course

public static fetchAttachmentsByCourse(int $courseId[, array<string, mixed> $params = [] ]) : array<string|int, MediaObject>
Parameters
$courseId : int

The course ID

$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, MediaObject>

Array of MediaObject instances

fetchAttachmentsByGroup()

Fetch media attachments for a specific group

public static fetchAttachmentsByGroup(int $groupId[, array<string, mixed> $params = [] ]) : array<string|int, MediaObject>
Parameters
$groupId : int

The group ID

$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, MediaObject>

Array of MediaObject instances

fetchByCourse()

Fetch media objects for a specific course

public static fetchByCourse(int $courseId[, array<string, mixed> $params = [] ]) : array<string|int, MediaObject>
Parameters
$courseId : int

The course ID

$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, MediaObject>

Array of MediaObject instances

fetchByGroup()

Fetch media objects for a specific group

public static fetchByGroup(int $groupId[, array<string, mixed> $params = [] ]) : array<string|int, MediaObject>
Parameters
$groupId : int

The group ID

$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, MediaObject>

Array of MediaObject instances

find()

Find a specific media object by ID Note: Canvas API doesn't support direct media object retrieval

public static find(int $id[, array<string|int, mixed> $params = [] ]) : self
Parameters
$id : int

The media object ID (not used - Canvas doesn't support this)

$params : array<string|int, mixed> = []

Optional query parameters

Tags
throws
CanvasApiException

Always throws as Canvas doesn't support this operation

Return values
self

get()

Fetch all media objects (global context)

public static get([array<string, mixed> $params = [] ]) : array<string|int, MediaObject>
Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, MediaObject>

Array of MediaObject instances

getTracks()

Get media tracks for this media object

public getTracks([array<string, mixed> $params = [] ]) : array<string|int, MediaTrack>
Parameters
$params : array<string, mixed> = []

Query parameters (include[] options)

Tags
throws
CanvasApiException
Return values
array<string|int, MediaTrack>

Array of MediaTrack objects

getTracksByAttachment()

Get media tracks by attachment ID

public getTracksByAttachment(int $attachmentId[, array<string, mixed> $params = [] ]) : array<string|int, MediaTrack>
Parameters
$attachmentId : int

The attachment ID

$params : array<string, mixed> = []

Query parameters (include[] options)

Tags
throws
CanvasApiException
Return values
array<string|int, MediaTrack>

Array of MediaTrack objects

toArray()

Convert the MediaObject to an array

public toArray() : array<string, mixed>
Return values
array<string, mixed>

updateTracks()

Update media tracks for this media object

public updateTracks(array<string|int, array<string, mixed>>|UpdateMediaTracksDTO $tracks[, array<string, mixed> $params = [] ]) : array<string|int, MediaTrack>
Parameters
$tracks : array<string|int, array<string, mixed>>|UpdateMediaTracksDTO

Track data

$params : array<string, mixed> = []

Query parameters (include[] options)

Tags
throws
CanvasApiException
Return values
array<string|int, MediaTrack>

Array of MediaTrack objects

updateTracksByAttachment()

Update media tracks by attachment ID

public updateTracksByAttachment(int $attachmentId, array<string|int, array<string, mixed>>|UpdateMediaTracksDTO $tracks[, array<string, mixed> $params = [] ]) : array<string|int, MediaTrack>
Parameters
$attachmentId : int

The attachment ID

$tracks : array<string|int, array<string, mixed>>|UpdateMediaTracksDTO

Track data

$params : array<string, mixed> = []

Query parameters (include[] options)

Tags
throws
CanvasApiException
Return values
array<string|int, MediaTrack>

Array of MediaTrack objects

castValue()

Cast a value to the correct type

protected castValue(string $key, mixed $value) : DateTime|mixed
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
DateTime|mixed

checkApiClient()

Check if the API client is set, if not, instantiate a new one

protected static checkApiClient() : void

convertPaginatedResponseToModels()

Helper method to convert paginated response data to model instances

protected static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
$paginatedResponse : PaginatedResponse
Return values
array<string|int, static>

getEndpoint()

Get the endpoint for this API resource MediaObjects don't have a single endpoint, so this throws an exception

protected static getEndpoint() : string
Tags
throws
CanvasApiException
Return values
string

getPaginatedResponse()

Helper method to get paginated response from API endpoint

protected static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
PaginatedResponse

populate()

Populate the object with new data

protected populate(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Tags
throws
Exception

toDtoArray()

Convert the object to an array

protected toDtoArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results