How to select radio link from api

this is my radio player provider ts code:

export class RadioPlayerProvider {
settings: any;
url: string;
stream: any;
promise: any;
data: any;
radio_url: any;

constructor(
private router: Router,
private apiService: ApiService,

) {
  this.getData();
this.url = "http://198.105.216.204:8064/";
this.stream = new Audio(this.url);

}
getData(){
this.apiService
.getappsettings(
settings?
)
.subscribe(settings => {
console.log(settings);
this.settings = settings;
});
}
play() {
this.stream.play();
this.promise = new Promise((resolve, reject) => {
this.stream.addEventListener(‘playing’, () => {
resolve(true);
});

  this.stream.addEventListener('error', () => {
    reject(false);
  });
});

return this.promise;

};

pause() {
this.stream.pause();
};

getStatus() {
return this.stream.playing==true ? ‘connected’ : ‘disconect’;
}

}
this is my api code where I have app_radio link:
this.apiService
.getappsettings(
settings?
)
.subscribe(settings => {
console.log(settings);
this.settings = settings;
});

I want to change this static url to dynamic to get it from api:
this.url = “http://198.105.216.204:8064/;stream1”;

I don’t get the Problem :thinking: You load the Settings and they included the URL you want? So why don’t you initialize the Player after this Request, something like:

this.apiService
.getappsettings(
settings?
)
.subscribe(settings => {
console.log(settings);
this.settings = settings;
this.url = settings.url; // or whatever
this.stream = new Audio(this.url);
});
1 Like

I am very new with ionic Sir,
can you write me code please?

This is not an Ionic Topic. It’s more about general Understanding of Angular and your Code. So am i right that this.apiService.getappsettings returns an object that includes the URL you want?

1 Like

yes:

  1. {,…}

  2. settings: [{apptbl_id: “1”, android_banner: “d7709bc38745daa6f16e6cbd1d1b9278”, ios_banner: “12548621”,…}]

1. 0: {apptbl_id: "1", android_banner: "d7709bc38745daa6f16e6cbd1d1b9278", ios_banner: "12548621",…}

  1. apptbl_id: "1"
  2. android_banner: "d7709bc38745daa6f16e6cbd1d1b9278"
  3. ios_banner: "12548621"
  4. android_interstitial: "ca-app-pub-3667704563169243/3287109053"
  5. ios_interstitial: "25987112"
  6. android_rewards: "ca-app-pub-3667704563169243/3661803131"
  7. ios_rewards: "fsdfsd5"
  8. is_testing_ads: null
  9. ads_after: "5"
  10. google_analytics: "UA-131801505-15"
  11. package: "rohi.af"
  12. apple_id: "1223544161"
  13. request_timeout: "30000"
  14. root_endpoint: "https://rohi.af/myapi/"
  15. share_android: "something about app"
  16. share_ios: "something about app"
  17. version: "001"
  18. version_ios: "001"
  19. onesignal_android_app_id: "a557a445-8fcb-436d-a695-b3ceacf848f3"
  20. onesignal_android_app_rest_api_key: "ZTNjOWQzOTYtODc4Mi00ODc1LWJlOGQtZjc4ZjgyODYzZjdj"
  21. onesignal_ios_app_id: "835013b8-2a48-4cdf-8146-7d53283cdf4d"
  22. onesignal_ios_app_rest_api_key: "YWQ4YjVjZmMtNThjMC00YWRmLTljMzMtNjk0Y2EyNGQzN2Ez"
  23. app_terms: "<h1 dir="ltr">Terms & Conditions</h1> ↵ ↵<div dir="ltr"> ↵<p>Please read the Terms & Conditions below carefully and confirm that you understand the content. Please consult with us for help if there are any issues related to the rights and benefits of the terms.</p> ↵ ↵<h2>1. Definitions</h2> ↵ ↵<ul> ↵ <li><strong>Users</strong> means a who access website.</li> ↵ <li><strong>Customers</strong> means a who buys Products made available for sale on the Sites.</li> ↵ <li><strong>Member</strong> means a person who signs up as a Member by creating an account.</li> ↵ <li><strong>Products</strong> mean products available for sale on the website including, but not limited to source code components and other forms of content in the form of creative digital computer files.</li> ↵ <li><strong>Payment Agent</strong> means any payment agent or method approved from time to time including, but not limited to, PayPal.</li> ↵</ul> ↵ ↵<h2>2. Agree</h2> ↵ ↵<p>– Users in the process of access, users have expressed the meaning of agreement and confirmation:</p> ↵ ↵<ol> ↵ <li>The user has read, fully understood and agrees to these terms.</li> ↵ <li>These regulations constitute a legally binding agreement on the user. If the user disagrees with any of the provisions of this policy, please do not access or attempt to use or continue to use.</li> ↵</ol> ↵ ↵<h2>3. Edit</h2> ↵ ↵<p>We reserve the right to revise as necessary, update and adjust the terms. Any such edits, updates or adjustments will be published public.<br> ↵Terms through modifications, updates, or adjustments will take effect once they are published.<br> ↵Consumers who continue to use the Services are deemed to have agreed and accepted the Terms and Conditions by modifying, updating, or adjusting them.<br> ↵Customer acknowledges and agrees to be solely responsible for reading, modifying, updating and / or modifying the foregoing.</p> ↵ ↵<h2>4. Benefits by Purchase</h2> ↵ ↵<p>By being purchase as a Customer you are entitled to:</p> ↵ ↵<ul> ↵ <li>Acquire a license to use that Product. This is dealt with in more detail in <strong>clause 6.</strong></li> ↵ <li>Request a support about that Product.</li> ↵ <li>Request a refund.</li> ↵ <li>Update changes of Product.</li> ↵</ul> ↵ ↵<h2>5. Fees and Services</h2> ↵ ↵<p>Membership is free.</p> ↵ ↵<p>If you are a Customers of a Product, you will pay a fee to buy the right to use that Product in accordance with <strong>clause 6</strong>.</p> ↵ ↵<p>All payments by Customers on the website must be paid using a Payment Agent.</p> ↵ ↵<p>You are responsible for paying all fees and taxes (including withholding tax), associated with your use of the website wherever levied (including any goods and services or value added taxes, which will be added to amounts billed to you, if applicable).</p> ↵ ↵<p>Payment will be made in US currency and accordance with the rules of the applicable Payment Agent. The Customers is responsible for all costs of currency conversion from his or her preferred currency to the US Dollar.</p> ↵ ↵<h2>6. Buying Products</h2> ↵ ↵<p>When you buy a Product, you acquire a license to use that Product. Products are subject to different terms of use – depending on the type of license that you choose when buying the Product.</p> ↵ ↵<p>If you do not select a license, you agree that the license you purchased is Regular License.</p> ↵ ↵<p>The different types of licenses and the conditions of use are set out in the licensing page.</p> ↵ ↵<p>Depending on the use you want to make of a Product, you will need to select the correct license required by you. You are responsible for choosing, and warrant that you have chosen, the correct license to meet your requirements.</p> ↵ ↵<p>If you buy a Product, you do so on the following terms:</p> ↵ ↵<ul> ↵ <li>Once your order for a Product is accepted, and you pay the fee, you acquire a non-exclusive license to use the Product in accordance with the conditions of the license that you acquire;</li> ↵ <li>Ownership of the Product remains with us.</li> ↵</ul> ↵ ↵<h2>7. Refunds</h2> ↵ ↵<p>If you want a refund or credit on a Product you must make a Refunds to Support. We will assess claims.</p> ↵ ↵<p>There is no obligation to provide a refund or credit for reasons including (but not limited to) if you:</p> ↵ ↵<ul> ↵ <li>Have changed your mind about a Product;</li> ↵ <li>Bought a Product by mistake;</li> ↵ <li>Do not have sufficient expertise to use the Product;</li> ↵ <li>Ask for goodwill;</li> ↵</ul> ↵ ↵<h2>8. Changes to pricing:</h2> ↵ ↵<p>Special deals might involve Products being sold for prices that are different to the advertised prices on Sites. This means that the fee payable to you is based on the revenue generated from the sales of your Products via our site, which may not always be determined by reference to the advertised price.</p> ↵ ↵<h2>9. Third Party Sites</h2> ↵ ↵<p>You may be able to link from the website to third party websites and third party websites may link to the website (<strong>Linked Sites</strong>).</p> ↵ ↵<p>You acknowledge and agree that we have no responsibility for the information, content, products, services, advertising, code or other materials which may or may not be provided by or through Linked Sites, even if they are owned or run by affiliates of ours.</p> ↵ ↵<p>The inclusion of a link to a Linked Site on the website does not constitute or indicate any relationship.</p> ↵ ↵<h2>10. Responsible</h2> ↵ ↵<p>Users are responsible and at risk for using the internet. We aren’t responsible for the accuracy, completeness, reliability or usefulness of any other information or process available. In no event shall we or its affiliates be liable for any indirect, consequential, or consequential damages.</p> ↵</div> ↵"
  24. app_privaicy: "<h1 dir="ltr">Privacy policy</h1> ↵ ↵<p dir="ltr"> </p> ↵ ↵<div> ↵<p dir="ltr">This privacy policy describes what information we collect and how <a href="https://rohi.af/page/8">we</a> use it.</p> ↵ ↵<p dir="ltr"> </p> ↵ ↵<h2 dir="ltr">I. What types of information do we collect?</h2> ↵ ↵<p dir="ltr">We use personally identifiable information provided by you.</p> ↵ ↵<h2 dir="ltr">II. How do we use this information?</h2> ↵ ↵<p dir="ltr">The purpose is to create account, login authentication on our server.</p> ↵ ↵<p dir="ltr">Show some information when you comment in post.</p> ↵ ↵<p dir="ltr">Send mail information about your account.</p> ↵ ↵<p dir="ltr">And used in our services, such as Delivery, Support when you buy a product.</p> ↵ ↵<h2 dir="ltr">III. Privacy: Transparency and choice</h2> ↵ ↵<p dir="ltr">Everyone has different concerns. The information we collect displays the details.</p> ↵ ↵<h2 dir="ltr">IV. Information we share</h2> ↵ ↵<p dir="ltr">We are committed not to share any information you provide.</p> ↵</div> ↵"
  25. app_about: "<p>مونږ څوګ يو؟<br> ↵روهي رسنيز مرکز له ۲۰۰۶ز کال راهېسې د ان لاين ژورنالېزم په برخه کې د هېواد له معتبرو رسنيو شمېرل کيږي. د دغه مرکز بنسټ د اورتوپدي برخې متخصص ډاکټر نېک محمد ويال اېښی او تر نن هم د روهي رسنيز مرکز د امتياز څښتن، بنسټګر او عمومي مسوول دی.<br> ↵د دغه رسنيز مرکز د تخنيکي برخې ډېرۍ چارې د ويال ټېک WeyalTech ټېکنالوژۍ شرکت له خوا سمباليږي. د روهي کلمې رېښه د روهستان، روهه او روهنيان کلمو څخه سرچينه اخلي چې يو وخت د افغانستان په غرنيو سيمو کې مېشتو پښتنو ته د وخت استعمارګرو او بهرنيو وګړو له خوا کارول کېدلې. د افغانستان د نورو قومونو ترمنځ پښتون قوم د تاريخ په مختلفو پيړيو کې په بيلا بيلو نومونو ياد شوی چې له دې جملې ورته ورهي، روهستان او روهه کلمې هم دوی او يا هم د دوی د استوګن ځاينونو ته کار ول شوې دي. روهي کلمه د تخلص په بڼه د هېواد د وتلي لېکوال او ملي شخصيت محمد صديق صیب تلخص هم پاتې شوی.<br> ↵روهي رسنيز مرکز د لومړنۍ موخې ترڅنګ هڅه کې چې د پښتو ژبې د ستر خدمتګار ښاغلي محمد صديق روهي صيب نوم هم ژوندی وساتي، خو په ماناوي او مادي ډول سره روهي رسنيز مرکز د ښاغلي محمد صديق روهي له درنې کورنۍ سره هېڅ ډول تړاو نه لري. روهي اسلامي نړۍ، ګران هېواد او په ځانګړې ډول پښتو ژبې ته د چوپړ په موخه په بې پرې، خپلواک او ناپېيلې ډول چوپړ کوي.</p> ↵"
  26. app_contact: "<p>له موږ سره مو اړیکه<br> ↵- تاسو کولی شئ، روهې وېب پاڼې ته په لاندې لارو لېکنې او ژباړې راولېږئ.<br> ↵۱- د روهي وېب پاڼې د برېښنليک له لارې: <a href="mailto:mail@rohi.af" title="mail@rohi.af">mail@rohi.af</a><br> ↵۲- د روهي وېب پاڼې د فېسبوک پاڼې له لارې: روهي وېبپاڼه<br> ↵۳- د روهي وېب پاڼې د اړيکو په برخه کې (زموږ سره مو اړیکې) د کړکي يا وينډو له لارې.<br> ↵په درنښت<br> ↵ډاکټر نيک محمد - ويال د روهي وېب پاڼې څښتن<br> ↵ <br> ↵د روهي ويب پاڼې اداره<br> ↵<a href="mailto:mail@rohi.af">mail@rohi.af</a> <br> ↵د روهي وېبپاڼې څښتن- نیک محمد ویال<br> ↵<a href="mailto:owner@rohi.af">owner@rohi.af</a> </p> ↵"
  27. app_radiolink: "http://198.105.216.204:8064/;stream1"
  28. app_videolink: "https://rtmp.api.rt.com/hls/rtdru.m3u8"

app_radiolink: “http://198.105.216.204:8064/;stream1

Everyone can see your Google Analytics Code, etc. you should not provide too much Info here maybe xD So after the Requests success, use the link included in the Settings to setup your Stream like i said before:

let me try it in my code

this.apiService.getappsettings(settings?).subscribe(settings => { console.log(settings);

    this.settings = settings; 

    this.url = settings.app_radiolink; 

    this.stream = new Audio(this.url); 

  });

got error:
Property ‘app_radiolink’ does not exist on type ‘Object’

try declare the type of settings as any for the moment. Later you should map it to a Class, because working with any sucks

export class RadioPlayerProvider {

settings: any;

url: string;

stream: any;

promise: any;

data: any;

radio_url: any;

constructor(

private http: HttpClient,

private router: Router,

private apiService: ApiService,



) {

  this.apiService

  .getappsettings(

    `settings?`

  )

  .subscribe(settings => {

    console.log(settings);

    this.settings = settings;

    this.url = settings.app_radiolink;

    this.stream = new Audio(this.url);

  });

looks like Settings is an Array with one Object. So use settings[0].app_radiolink

I am so sorry for disterbing you
still not responding ((

I will pay if you can connect with me