Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4665] iPhone: AudioPlayer does not play streaming media

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2011-08-08T13:43:30.000+0000
Affected Version/sRelease 1.7.1
Fix Version/sSprint 2011-32
ComponentsiOS
Labelsn/a
ReporterMiguel Vizcaino
AssigneeBlain Hamon
Created2011-07-13T16:03:21.000+0000
Updated2017-03-29T21:52:34.000+0000

Description

Problem:

AudioPlayer does not play streaming media over the Internet. {quote} This works fine on url / files but not on streams like SHOUTcast http://www.shoutcast.com I have never gotten the onload / onerror event fired on a XMLHttpRequest

Customer

wants to avoid -> File Error: _"Unable to configure network read stream"_ {quote}
var audio_stream = Titanium.Media.createAudioPlayer();
var playing = false;
var now_playing_data_timer = undefined;
var tabGroup = Ti.UI.createTabGroup();
  
var win = Titanium.UI.createWindow({  
    title:'Listen',
    backgroundColor:'#000'
});
var tab = Titanium.UI.createTab({  
   	icon:'KS_nav_views.png',
   	title:'Listen',
   	window:win
});
var text = Titanium.UI.createLabel({
  	color:'blue',
  	text:'Song:',
  	width:'auto',
  	top: 0,
  	left:0
});  
var imageview = Titanium.UI.createImageView({
  	image:"http://2.bp.blogspot.com/_ZqpzRV9D624/TNnn-FLSgmI/AAAAAAAAAAs/8ca4flYJKhg/S350/logo%2Bde%2Bmusica%2B1.png",
  	height:100,
  	width:110,
  	top:150,
  	backgroundColor:'white'
});
var play_button = Titanium.UI.createButton({
    image: "playbutton.png",
    width: 110,
    height: 80,
    top: 10,
    title:"Play",
    color: "red"
});
var play_stream = function(stream_url){
   	playing = true;
    audio_stream.setUrl(stream_url);
    audio_stream.start();
};
var stop_stream = function(){
    playing = false;
    audio_stream.stop();
};
win.addEventListener('open', function(e) {
	init();
});  
var init = function() {
	win.add(text);
    win.add(play_button);
    win.add(imageview);
}; 
play_button.addEventListener('click',function()
{
    var xhr = Ti.Network.createHTTPClient();
 	var stream_url = 'http://yp.shoutcast.com/sbin/tunein-station.pls?id=1268400';

	xhr.onload = function(e) {
		playing = true;
  		audio_stream.setUrl(stream_url);
    	audio_stream.start();
	};
 
	xhr.onerror = function(e) {
		alert(e.error);
	};
 	xhr.setTimeout(10000);
	xhr.open('GET', stream_url);
	xhr.file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'tunein-station.pls');
	xhr.send(); 	
});
tabGroup.addTab(tab);
tabGroup.open();

Associated Helpdesk Ticket

http://support.appcelerator.com/tickets/APP-577977

Attachments

FileDateSize
playbutton.png2011-07-13T16:03:21.000+00003223

Comments

  1. Blain Hamon 2011-08-08

    The url in the sample code does not contain a stream. Instead, it is a text file, not sound. It is the end developer's responsibility to parse the text file, find urls in it that actually _are_ of streams, and then pass a stream url to audioPlayer.
  2. Alexis Gaitan 2012-09-23

    same issue, can be fixed?
  3. Lee Morris 2017-03-29

    Closing ticket as invalid.

JSON Source