Play Music

    This example plays the audio file Trumpet.mp3 to the caller.

    Response

    <Response>
        <Play>https://s3.amazonaws.com/plivocloud/Trumpet.mp3</Play>
    </Response>
    

    Example Request

    1
    2
    3
    4
    5
    
    from plivo import plivoxml
    
    response = plivoxml.ResponseElement()
    response.add(plivoxml.PlayElement('https://s3.amazonaws.com/Trumpet.mp3'))
    print(response.to_string())
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    require 'rubygems'
    require 'plivo'
    
    include Plivo::XML
    include Plivo::Exceptions
    
    begin
      response = Response.new
    
      play_body = 'https://s3.amazonaws.com/plivocloud/Trumpet.mp3'
      response.addPlay(play_body)
    
      xml = PlivoXML.new(response)
      puts xml.to_xml
    rescue PlivoXMLError => e
      puts 'Exception: ' + e.message
    end
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    var plivo = require('plivo');
    
    var response = plivo.Response();
    
    var play_body = "https://s3.amazonaws.com/plivocloud/Trumpet.mp3";
    response.addPlay(play_body);
    
    console.log(response.toXML());
    
    /*
    Sample Output
    <Response>
        <Play>
            https://s3.amazonaws.com/plivocloud/Trumpet.mp3 
        </Play>
    </Response>
    */
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    <?php
        require '../vendor/autoload.php';
        use Plivo\XML\Response;
    
        $response = new Response();
    
        $play_body = "https://s3.amazonaws.com/plivocloud/Trumpet.mp3";
        $response->addPlay($play_body);
    
        Header('Content-type: text/xml');
        echo($response->toXML());
    
        /*
        Sample Output
    
        <Response>
            <Play>
                https://s3.amazonaws.com/plivocloud/Trumpet.mp3
            </Play>
        </Response>
        */
    ?>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    // Example for xml - play music
    package com.plivo.api.xml.samples.xml;
    
    import com.plivo.api.exceptions.PlivoXmlException;
    import com.plivo.api.xml.Play;
    import com.plivo.api.xml.Response;
    
    
    class PlayMusic {
        public static void main(String[] args) throws PlivoXmlException {
            Response response = new Response()
                    .children(
    
    
                            new Play("https://s3.amazonaws.com/Trumpet.mp3")
    
                    );
            System.out.println(response.toXmlString());
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    using System;
    using System.Collections.Generic;
    using Plivo.XML;
    
    namespace Plivo
    {
    	class MainClass
    	{
    		public static void Main(string[] args)
    		{
    			Plivo.XML.Response resp = new Plivo.XML.Response();
    			resp.AddPlay("https://amazonaws.com/Trumpet.mp3",
    					  new Dictionary<string, string>() { });
    
    			var output = resp.ToString();
    			Console.WriteLine(output);
    
    		}
    	}
    }
    
    
    
    //<Response>
    //  <Play>https://amazonaws.com/Trumpet.mp3</Play>
    //</Response>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    // Example for xml - play music
    package main
    
    import "github.com/plivo/plivo-go/xml"
    
    
    func main() {
    	response := xml.ResponseElement{
    		Contents: []interface{} {
    			
    
    
    			new(xml.PlayElement).
    			SetContents("https://s3.amazonaws.com/Trumpet.mp3"),
    
    		},
    	}
    	print(response.String())
    }