Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a second format (.ogg) to audioPlayer

Status
Not open for further replies.

jml7

Programmer
Sep 28, 2010
3
US
My audioPlayer works just like I want it to. The only issue I have is trying to list a second type of audio file in an Array. I have .m4a files right now which work great in Safari and Chrome, but I need .ogg files for it to work in Firefox. Does anyone know the proper way to list a second format? Here is my code:

Code:
var urls = new Array();
        urls[0] = 'audio/song1.m4a';
        urls[1] = 'audio/song2.m4a';
        urls[2] = 'audio/song3.m4a';
        urls[3] = 'audio/song4.m4a';
        urls[4] = 'audio/song5.m4a';
        urls[5] = 'audio/song6.m4a';
	var next = 0;
 
If you want to add .ogg files into your array, the syntax is exactly the same:

Code:
urls[6] = 'audio/song7.ogg';

If your audio player cannot handle .ogg files, then you'll need to find another audio player.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Hi

I think the OP not wants to append one more item to the current list, but to have an alternative to the whole list.
Code:
[b]var[/b] allurls[teal]=[/teal][teal]{[/teal]
  [green][i]'webkit'[/i][/green][teal]=[[/teal]
    [green][i]'audio/song1.m4a'[/i][/green][teal],[/teal]
    [green][i]'audio/song2.m4a'[/i][/green][teal],[/teal]
    [green][i]'audio/song3.m4a'[/i][/green][teal],[/teal]
    [green][i]'audio/song4.m4a'[/i][/green][teal],[/teal]
    [green][i]'audio/song5.m4a'[/i][/green][teal],[/teal]
    [green][i]'audio/song6.m4a'[/i][/green]
  [teal]],[/teal]
  [green][i]'gecko'[/i][/green][teal]=[[/teal]
    [green][i]'audio/song1.ogg'[/i][/green][teal],[/teal]
    [green][i]'audio/song2.ogg'[/i][/green][teal],[/teal]
    [green][i]'audio/song3.ogg'[/i][/green][teal],[/teal]
    [green][i]'audio/song4.ogg'[/i][/green][teal],[/teal]
    [green][i]'audio/song5.ogg'[/i][/green][teal],[/teal]
    [green][i]'audio/song6.ogg'[/i][/green]
  [teal]][/teal]
[teal]}[/teal]
Then choose from the two arrays before using :
Code:
urls[teal]=[/teal]allurls[teal][[/teal]isThisWebkitBrowser[teal]?[/teal][green][i]'webkit'[/i][/green][teal]:[/teal][green][i]'gecko'[/i][/green][teal]][/teal] [gray]// (*)[/gray]

But probably that is redundant, as the file names will probably differ only in extensions.
Code:
[b]var[/b] urls[teal]=[[/teal]
  [green][i]'audio/song1.'[/i][/green][teal],[/teal]
  [green][i]'audio/song2.'[/i][/green][teal],[/teal]
  [green][i]'audio/song3.'[/i][/green][teal],[/teal]
  [green][i]'audio/song4.'[/i][/green][teal],[/teal]
  [green][i]'audio/song5.'[/i][/green][teal],[/teal]
  [green][i]'audio/song6.'[/i][/green]
[teal]][/teal]
[b]for[/b] [teal]([/teal][b]var[/b] i[teal]=[/teal][purple]0[/purple][teal],[/teal]l[teal]=[/teal]urls[teal].[/teal]length[teal];[/teal]i[teal]<[/teal]l[teal];[/teal]i[teal]++)[/teal]
  urls[teal][[/teal]i[teal]]+=[/teal]isThisWebkitBrowser[teal]?[/teal][green][i]'m4a'[/i][/green][teal]:[/teal][green][i]'ogg'[/i][/green] [gray]// (*)[/gray]
(*) The ternary operator's condition is just for example. There is no such variable.

In case you use HTML 5 and its [tt]audio[/tt] tag, take a look at Modernizr. It will simplify the detection of recognized formats.


Feherke.
 
Thanks for your responses! feherke was right in that I am looking to add on to the first list.

I am new to javascript so I'm not sure how to choose from the two extensions. Any chance one of you could help me with this?

Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top