Getting started
Designing apps
Fundamentals
Platform concepts
Developing apps
Authenticating usersCreating app elementsCreating audio tracksCreating imagesCreating image overlaysCreating shapesCreating tablesCreating textCreating videosDesign editingEmbedding rich mediaExporting designsGrouping elementsLocalizationPositioning elementsQuerying contentReading elementsReplacing elementsSupporting drag and dropUsing color selectorsUsing design IDsUsing fonts
Resources
Securing apps
Monetizing apps
Distributing apps
DraggableAudio
API reference for the DraggableAudio component.
The DraggableAudio
component has been deprecated. Instead, use the AudioCard
(opens in a new tab or window) component.
Usage
import React from "react";import { AudioContextProvider } from "components/audio_context";import { DraggableAudio } from "components/draggable_audio";import { upload } from "@canva/asset";export function App() {return (<AudioContextProvider><DraggableAudiotitle="Example audio"durationMs={86047}previewUrl="https://www.canva.dev/example-assets/audio-import/audio.mp3"resolveAudioRef={() => {return upload({type: "audio",title: "Example audio",mimeType: "audio/mp3",url: "https://www.canva.dev/example-assets/audio-import/audio.mp3",aiDisclosure: "none",});}}/></AudioContextProvider>);}
TSX
The AudioContextProvider
component ensures that only one audio file will play at a time.
Props
title
string
RequiredA human-readable title that appears in the Canva editor.
url
string
RequiredThe URL of the audio file.
previewUrl
string
RequiredThe URL of the audio file to play when the user clicks the Play button.
durationMs
number
RequiredThe duration of the audio file, in milliseconds.
resolveAudioRef
function
RequiredA function that returns the result of the upload
method.