How to retrieve audio information like length of audio file? Rails App

Comments

5 comments

  • Avatar
    Stephen Doyle

    Hi Ilia,

    When you upload a new asset and specify the 'image_metadata' parameter in the API call or Upload Preset, we'll include details of the newly-uploaded file in our Upload API response, including the duration of audio and video assets.

    For example, for a random m4a file that I uploaded to my own account, the response with image_metadata=true, contains:

    ...
    audio:
    { codec: 'aac',
    bit_rate: '134511',
    frequency: 48000,
    channels: 2,
    channel_layout: 'stereo' },
    video: {},
    is_audio: true,
    bit_rate: 144577,
    duration: 3.540146,
    original_filename: 'test' }

    You can also obtain that  information for existing assets via the 'get resources' method of our Admin API, and use that to synchronise your own database.

    If you'll need to refer to this information on the client-side, and can't store it in your own database, another option is to store the duration in the asset's 'context' metadata, the values of which are returned if you use our client-side asset list feature: https://cloudinary.com/documentation/advanced_url_delivery_options#client_side_asset_lists

    In your case, you could add  tag to all assets that are on the same playlist, then use the .json list for that playlist to get the asset details? Regarding how to move from one file to the next, I don't think there are helper methods for this in Rails specifically, but our video player does support an API for adding multiple files to a playlist, and sends events you can use to detect when a track completes so you change the contents of the playlist: 
    https://cloudinary.com/documentation/video_player_playlists_recommendations
    https://cloudinary.com/documentation/video_player_events_analytics

    Please let me know if that helps and if there's anything else I can help with

    Regards,

    Stephen

    1
    Comment actions Permalink
  • Avatar
    Ilia Zolas

    Thanks Stephen,

    I think that's just about all the info I need to continue. Thanks so much for your response! Will relay back here if I have anything to add about the topic.

    Ilia

    0
    Comment actions Permalink
  • Avatar
    Stephen Doyle

    You're welcome; please let me know if you have further questions, and if you have any account-specific questions you can also contact my team directly via the "submit a request" link here on our support site

    Regards,

    Stephen

    0
    Comment actions Permalink
  • Avatar
    benjaminky

    So how will this be when used for android?. I want to use this feature for android to get mp3 file information for a music player.

    0
    Comment actions Permalink
  • Avatar
    Wissam Khalili

    Hi there,

    Sorry for the late response.

    You could use our upload method and others using Android SDK.

    Please review the following guide:
    https://cloudinary.com/documentation/android_image_and_video_upload

    Best Regards,

    Wissam

     

    0
    Comment actions Permalink

Please sign in to leave a comment.