Skip to content

Commit

Permalink
Minor tweaks so that the App can run
Browse files Browse the repository at this point in the history
  • Loading branch information
MKuckert committed Sep 7, 2017
1 parent b66e140 commit 545565b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
10 changes: 10 additions & 0 deletions Samples/Official Demo/DemoApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

using System;
using Android.App;
using Android.Runtime;
using Com.Google.Android.Exoplayer2.Upstream;
using Utils = Com.Google.Android.Exoplayer2.Util.Util;

Expand All @@ -27,6 +29,14 @@ public class DemoApplication : Application
{
protected string userAgent;

public DemoApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}

public DemoApplication()
{
}

public override void OnCreate()
{
base.OnCreate();
Expand Down
2 changes: 1 addition & 1 deletion Samples/Official Demo/PlayerActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void initializePlayer()
{
mediaSource = CreateAdsMediaSource(mediaSource, Uri.Parse(adTagUriString));
}
catch (System.Exception e)
catch (System.Exception)
{
ShowToast(Resource.String.ima_not_loaded);
}
Expand Down
54 changes: 31 additions & 23 deletions Samples/Official Demo/SampleChooserActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Java.IO;
using Java.Lang;
using Java.Util;
using Java.Interop;

namespace Com.Google.Android.Exoplayer2.Demo
{
Expand Down Expand Up @@ -81,7 +82,7 @@ protected override void OnCreate(Bundle savedInstanceState)
}
}
}
catch (System.Exception e)
catch (System.Exception)
{
Toast.MakeText(ApplicationContext, Resource.String.sample_list_load_error, ToastLength.Long)
.Show();
Expand Down Expand Up @@ -110,7 +111,7 @@ private void onSampleSelected(Sample sample)
StartActivity(sample.buildIntent(this));
}

private sealed class SampleListLoader : AsyncTask<string, Java.Lang.Void, List<SampleGroup>>
private sealed class SampleListLoader : AsyncTask<string, Void, List<SampleGroup>>
{
private bool sawError;
private SampleChooserActivity context;
Expand All @@ -120,27 +121,27 @@ public SampleListLoader(SampleChooserActivity context)
this.context = context;
}

protected override List<SampleGroup> RunInBackground(params string[] uris)
protected override List<SampleGroup> RunInBackground(params string[] @params)
{
var result = new List<SampleGroup>();
var userAgent = Util.Util.GetUserAgent(context, "ExoPlayerDemo");
var dataSource = new DefaultDataSource(context, null, userAgent, false);
foreach (var uri in uris)
foreach (var uri in @params)
{
var dataSpec = new DataSpec(global::Android.Net.Uri.Parse(uri));
var inputStream = new DataSourceInputStream(dataSource, dataSpec);
var memory = new MemoryStream();
var buffer = new byte[1024];
while (inputStream.Available() > 0)
int read;
while ((read = inputStream.Read(buffer)) > 0)
{
inputStream.Read(buffer);
memory.Write(buffer, 0, buffer.Length);
memory.Write(buffer, 0, read);
}
memory.Seek(0, SeekOrigin.Begin);

try
{
readSampleGroups(new JsonReader(new InputStreamReader(memory, "UTF-8")), result);
ReadSampleGroups(new JsonReader(new InputStreamReader(memory, "UTF-8")), result);
}
catch (System.Exception e)
{
Expand All @@ -155,22 +156,29 @@ protected override List<SampleGroup> RunInBackground(params string[] uris)
return result;
}

protected override void OnPostExecute(Object result)
{
base.OnPostExecute(result);
// This overload is required so that the following overload is also called?! ¯\_(ツ)_/¯
}

protected override void OnPostExecute(List<SampleGroup> result)
{
base.OnPostExecute(result);
context.onSampleGroups(result, sawError);
}

private void readSampleGroups(JsonReader reader, List<SampleGroup> groups)
private void ReadSampleGroups(JsonReader reader, List<SampleGroup> groups)
{
reader.BeginArray();
while (reader.HasNext)
{
readSampleGroup(reader, groups);
ReadSampleGroup(reader, groups);
}
reader.EndArray();
}

private void readSampleGroup(JsonReader reader, List<SampleGroup> groups)
private void ReadSampleGroup(JsonReader reader, List<SampleGroup> groups)
{
var groupName = "";
var samples = new List<Sample>();
Expand All @@ -188,7 +196,7 @@ private void readSampleGroup(JsonReader reader, List<SampleGroup> groups)
reader.BeginArray();
while (reader.HasNext)
{
samples.Add(readEntry(reader, false));
samples.Add(ReadEntry(reader, false));
}
reader.EndArray();
break;
Expand All @@ -201,11 +209,11 @@ private void readSampleGroup(JsonReader reader, List<SampleGroup> groups)
}
reader.EndObject();

SampleGroup group = getGroup(groupName, groups);
SampleGroup group = GetGroup(groupName, groups);
group.samples.AddRange(samples);
}

private Sample readEntry(JsonReader reader, bool insidePlaylist)
private Sample ReadEntry(JsonReader reader, bool insidePlaylist)
{
string sampleName = null;
string uri = null;
Expand Down Expand Up @@ -235,7 +243,7 @@ private Sample readEntry(JsonReader reader, bool insidePlaylist)
break;
case "drm_scheme":
Assertions.CheckState(!insidePlaylist, "Invalid attribute on nested item: drm_scheme");
drmUuid = getDrmUuid(reader.NextString());
drmUuid = GetDrmUuid(reader.NextString());
break;
case "drm_license_url":
Assertions.CheckState(!insidePlaylist,
Expand Down Expand Up @@ -266,7 +274,7 @@ private Sample readEntry(JsonReader reader, bool insidePlaylist)
reader.BeginArray();
while (reader.HasNext)
{
playlistSamples.Add((UriSample)readEntry(reader, true));
playlistSamples.Add((UriSample)ReadEntry(reader, true));
}
reader.EndArray();
break;
Expand All @@ -292,7 +300,7 @@ private Sample readEntry(JsonReader reader, bool insidePlaylist)
}
}

private SampleGroup getGroup(string groupName, List<SampleGroup> groups)
private SampleGroup GetGroup(string groupName, List<SampleGroup> groups)
{
for (int i = 0; i < groups.Count; i++)
{
Expand All @@ -306,7 +314,7 @@ private SampleGroup getGroup(string groupName, List<SampleGroup> groups)
return group;
}

private UUID getDrmUuid(string typeString)
private UUID GetDrmUuid(string typeString)
{
switch (typeString.ToLowerInvariant())
{
Expand All @@ -321,7 +329,7 @@ private UUID getDrmUuid(string typeString)
{
return UUID.FromString(typeString);
}
catch (RuntimeException e)
catch (RuntimeException)
{
throw new ParserException("Unsupported drm type: " + typeString);
}
Expand All @@ -340,7 +348,7 @@ public SampleAdapter(Context context, List<SampleGroup> sampleGroups)
this.sampleGroups = sampleGroups;
}

public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
public override Object GetChild(int groupPosition, int childPosition)
{
return sampleGroups[groupPosition].samples[childPosition];
}
Expand Down Expand Up @@ -368,7 +376,7 @@ public override int GetChildrenCount(int groupPosition)
return sampleGroups[groupPosition].samples.Count;
}

public override Java.Lang.Object GetGroup(int groupPosition)
public override Object GetGroup(int groupPosition)
{
return sampleGroups[groupPosition];
}
Expand Down Expand Up @@ -401,7 +409,7 @@ public override bool IsChildSelectable(int groupPosition, int childPosition)
}
}

internal sealed class SampleGroup : Java.Lang.Object
internal sealed class SampleGroup : Object
{

public readonly string title;
Expand All @@ -414,7 +422,7 @@ public SampleGroup(string title)
}
}

internal abstract class Sample : Java.Lang.Object
internal abstract class Sample : Object
{
public readonly string name;
public readonly bool preferExtensionDecoders;
Expand Down

0 comments on commit 545565b

Please sign in to comment.