Only loading first 5 seconds of a MP3 File

I have a MP3 file on my server that is 30 seconds long. I only want to play the first 5 seconds as a "preview".

Currently I am loading the full MP3 and then playing the file through AVAudioPlayer for the first 5 seconds. The issue I have with this is if the user is not on a WiFi network, this eventually can become expensive in terms of the user's data plan. I thought of finding a way to cut off downloading of the file after x amount (which I would have to calculate) of data is sent but not sure if this would be the right solution.

Any suggestions are appreciated.

-------------Problems Reply------------

If you want to stream audio, try AVPlayer.

You can use NStimer:

[NSTimer scheduledTimerWithTimeInterval:numberOfSeconds

When you start streaming just fire timer and in stopAudio method stop streaming audio after numberOfSeconds seconds.

According to this post, AVA is not the best for streaming audio :

Streaming with an AVAudioplayer

Hope it helps

Category:ios Views:1 Time:2019-01-28

Related post

  • Ruby's YAML only loads first Records from a large File, why? 2011-01-27

    Okay, I have the following YAML file that was generated by using yaml_db for Rails. So this is basically an autogenerated export of my Rails database: --- admins: columns: - id - username - email - encrypted_password - password_salt - sign_in_count -

  • How to create 30 seconds clips of .mp3 files in C# on desktop client software? 2011-04-08

    I wanted to find out if there is a way to create 30 second clips (with a start time in seconds) of .wav or .mp3 files in C# (or using a C# library). Most of the code or libraries I've seen seem related to recording and playback, but what if you just

  • When loading my video to Windows movie maker, it will only load 11 seconds of a 5 minute video. 2012-02-05

    I am trying to make a video. The video is a Mpeg-2. It's a little over 5 minutes long. I have tried numerous times to load the video but each time it will only play 11 seconds. Whenever I play the video through windows media player it will play the e

  • Open only the first few lines of a file in Vim 2011-03-21

    I'm working with a CSV that's just shy of 1 GB. I want to see the the file's structure and a sample of the data, but I don't want to open the entire file. How can I load the first few rows in Vim? If it makes a difference, I'm using MacVim. ---------

  • Pagination not working properly in IE (only loading first item) 2011-04-18

    I added JQuery Pagination to my online portfolio. Here is the link: It seems to work fine in Chrome and Firefox, but only the first item gets loaded in IE. Can someone take a look? Thanks. EDIT Here is the code JQuer

  • Can I grep only the first n lines of a file? 2012-01-06

    I have very long log files, is it possible to ask grep to only search the first 10 lines? --------------Solutions------------- The magic of pipes; head -10 log.txt | grep <whatever> Or use awk for a single process without |: awk '/your_regexp/

  • Copy the first, second,.. 500 Files of a directory? 2012-01-31

    I have a directory containing more than 27000 images. I want to split these files into folders each containing around 500 images. It doesnt matter how they are sorted, I just want to separate them. I would like to do it with a simple bash script. Che

  • ffmpeg segments only the first part of my audio file 2012-04-20

    I'm implementing a http live streaming server to send audio file to iOS devices. No problem with Apple's tools, mediafilesegmenter, my files are valid and it works fine. I'm trying now to segment the same file using ffmpeg. I've downloaded the last s

  • Breeze Extended Entity Property Only Loads on Second Query 2013-09-19

    Hopefully someone has a better insight into Breeze's Extended entities, because I'm stumped! So, I have created a partial class (WO_Rout) on the server side (Web API using Breeze's API) and created a property named "AssetJobEqNo". I have read and fol

  • Apache only serves first level of Django static files directory 2011-09-11

    I have a site I made with Django, and I'm trying to deploy it on an Apache server I have lying around (using mod_wsgi as recommended by the official docs) and for the most part, everything's going great. I am having a problem getting Apache to correc

  • Join Merge only the first two lines of a file using AWK or SED 2014-12-23

    I have a file like this Line1 Line2 Line3 Line4 Line5 I need the output like this: Line1Line2 Line3 Line4 Line5 I tried sed ":a;N;$!ba;s/\n//g" asd.txt but it combines all lines into one. --------------Solutions------------- You could try the below s

  • UIImage only loads on iPhone if I change file name to lowercase 2010-08-21

    I have an image that changes due to a button press. I have the code set up like this: UIImage *example = [UIImage imageNamed: @"Example.png"]; UIImage *stuff = [UIImage imageNamed: @"Stuff.png"]; UIImage *bob = [UIImage imageNamed: @"Bob.png"]; UIIma

  • How to download only the first part of a .csv file on Android? 2010-11-09

    In my app, I have to present a few numbers from a .csv file that's accessible from the web. Now, this .csv is quite big. I don't want to download and process the whole thing, there's no point. My numbers are always in the beginning of the file, in we

  • SSIS - I need to import only the first row from a flat file. What's the best approach? 2011-03-18

    I have a file that contains a header record in the 1st row, and I need to evaluate only that one row. The rest of the rows are detail records. I have it set up now as a flat file source component into a conditional split. The job of the conditional s

  • How can I view only the first n lines of the file? 2009-09-11

    I tried head +10 and it didn't work. --------------Solutions------------- Did you try the manpage for head? head -n 10 filename Head is a fine tool, but you might also try: sed 10q path For code golf fanatics, sed is always better than head :)

  • C# : concatenate 2 MP3 files 2009-09-21

    I tried to concatenate 2 MP3 files using the code below. I got a new file which I can play the first half of (complete first file), but the second half is silent. The length of the new file was correct. What do I do wrong? List<Byte[]> files =

  • onstop() for mp3 files 2010-12-24

    i have this two i press the first it plays an mp3 file.but if i press the second and the first mp3 hasnt finished yet,they play both could i fix it??this is my btn code!!thanks Button button = (Button) findViewById(; b

  • Is there any way I could change the order of which Apache VirtualHosts load first? 2010-08-25

    I'm using a wildcard subdomain to manage most of my requests but I'm running into an issue of getting one of my subdomains (let's say, to load first. I understand that loading this inside an httpd.conf or something would just be a ca

  • How do I change the music to MP3 files? 2012-08-08

    How do I change the music I loaded on my computer to MP3 files to put on my phone? --------------Solutions------------- Hi, What is the extension of the file that you want to convert? You might need to install additional third party software to conve

  • why is my zune missing some mp3 files? 2013-11-21

    What could be the reason the zune software only recognize a few mp3 files and not others? I have a bunch of old mp3 files that I want to sync with my zune. But the zune software can recognize only 2 out of almost 100 mp3 files. No matter how I rename

  • Adobe Air encryption of mp3 file with as3crypto only encrypts the first few bytes 2010-08-08

    I am using the as3crypto library to encrypt mp3 files in an Adobe Air application. The code below runs without error but I realized that only the first few bytes of the mp3 file are getting encrypted but not the whole file. I have no idea what’s the

  • .voib files only load the first frame 2012-03-26

    Question Summary I have questions about supported file types in Windows Live Movie Maker Which version of Windows Live Movie Maker are you using ? Version 2011 (15.4.3538.513) Choose your Operating System version : Windows 7 Additional Details I am t

  • I wish to create an icon on my desktop to load 2 programs. I tried a .bat file, but it only loads the first program. 2013-06-07

    I wish to create an icon on my desktop to load 2 programs. I tried a .bat file, but it only loads the first program. --------------Solutions------------- Does this help you in any way? Microsoft® Security MVP, 2004 - 2009 Yup. That did it, Thanks!

  • How can I change the duration of an MP3 file I have downloaded? For instance, I have a song that last 1,5 minute, but I only want to keep 21 seconds. How can I crop it? 2015-02-13

    How can I change the duration of an MP3 file I have downloaded? For instance, I have a song that last 1,5 minute, but I only want to keep 21 seconds. How can I crop it? --------------Solutions------------- How can I change the duration of an MP3 file

  • Loading and playing more than one .mp3 file 2010-10-25

    I'm trying to set up a .flv file that will have buttons for two different pieces of sound. I've been able to get the first piece to load and to play and stop, but when I try to load the second piece, I trip up. I'm still a novice, but do think I unde

Copyright (C), All Rights Reserved.

processed in 0.188 (s). 11 q(s)