playing a local video in a uiwebview - objective-c

i load a local html file into an ipad application:
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *path = [[NSBundle mainBundle] pathForResource:#"lieferant1" ofType:#"html"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:content baseURL:baseURL];
the webpage gets displayed, content of my html file:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>
<video>
<source src="banane.m4v">
</video>
</p>
so, banane.m4v is in my root, just in some groups, but not in real directories.
but the video section in my webview keeps black. no video gets loaded. i uploaded my html file and my .m4v video to my webserver to check if its not encoded properly, but everything works fine, surfing the html file with my ipad.
some ideas whats wrong?

oh my god
<video controls>
<source src="banane.m4v">
</video>
where controls is the magic word.
:X

I may be wrong (or silly) but, did you try file:///banane.m4v (Add the extra '/' for root)

For everyone that experiences a crossed out play symbol,
When you drag your movie-files (mp4's work as well, just make sure the codec is okay - easiest way is to export for iPhone with QuickTime) a dialog appears.
Make sure you tick your app under "add to targets".
Or if you already copied your video into the project, if you click it in Xcode's file browser, you'll have an option on the right-hand side to select targets.

You need to set the allowsInlineMediaPlayback property on the UIWebView:
[webView setAllowsInlineMediaPlayback:YES];

Related

React native gesture handler overwrites on android but not on ios

I was wondering why my react native if i wrap scrollview with gesture detector, I'm unable to scroll on android but able to scroll on ios. I was wondering how I can make my scrollview work on android.
Thanks!
const gest = Gesture.Pan().onUpdate((e) => {...})
return(
<GestureDetector gesture={roomGestureTV}>
<ScrollView ... />
</GestureDetector>
)
Here is a Snack that shows how to wrap a ScrollView with a PanGesture (Snack or below for future reference). I have tested the code on a Galaxy S9 (Android) and iPhone 13 (Real and Emulator).
Some notes (See the snack first!):
The behaviour for android and IOS gestures differs, because they (react-native-gesture-handler) had to implement a custom solution on Android but not on IOS. On Android the pan gesture cancels the ScrollView gesture, but on IOS the ScrollView cancels the PanGesture. In both cases PanGesture and Scroll gesture do not work simultanously out of the box.
Use createNativeWrapper instead of the ScrollView from gesture handler. While the ScrollView from gesture handler will work, other components that build on ScrollView will not (e.g. FlatLists). In order to use a FlatList instead of a ScrollView, exchange the ScrollView with a FlatList in createNativeWrapper
createNativeWrapper is no longer activly supported by the libary (Source). However, the new/old Native Gesture Component is not working for this use case (at least for me). This might be a bug and might be fixed in newer versions.
Note that simultaneousHandlers for the ScrollView is not limited to one gesture but can accept multiple gestures. E.g. it is possible to have a pan and pinch gesture while scrolling.
Reference Code
import React, { useRef } from 'react';
import { Text, View, ScrollView } from 'react-native';
import Animated, {
useDerivedValue,
useSharedValue,
useWorkletCallback,
} from 'react-native-reanimated';
import {
createNativeWrapper,
GestureHandlerRootView,
Gesture,
GestureDetector,
} from 'react-native-gesture-handler';
import ReText from './components/ReText';
/**
* Gesture states
* (see https://docs.swmansion.com/react-native-gesture-handler/docs/under-the-hood/states-events)
*/
const STATES = {
0: 'UNDETERMINED',
1: 'FAILED',
2: 'BEGAN',
3: 'CANCELLED',
4: 'ACTIVE',
5: 'END',
};
const CustomScrollComponent = createNativeWrapper(ScrollView)
export default function App() {
const panRef = useRef(null);
const scrollRef = useRef(null);
// Log values
const touchPosition = useSharedValue({ x: null, y: null });
const touchPositionX = useDerivedValue(() => {
return `x: ${touchPosition.value.x}`;
});
const touchPositionY = useDerivedValue(() => {
return `y: ${touchPosition.value.y}`;
});
const state = useSharedValue([STATES[0], 'null', 'null']);
const stateString = useDerivedValue(() => {
return `${state.value[0]}\n${state.value[1]}\n${state.value[2]}`;
});
const appendState = useWorkletCallback((arr, value) => {
return [value].concat(arr.slice(0, 2));
}, []);
const panGesture = Gesture.Pan()
.onBegin((e) => {
state.value = appendState(state.value, STATES[e.state]);
})
.onStart((e) => {
state.value = appendState(state.value, STATES[e.state]);
})
.onUpdate((e) => {
if (state.value[0] !== STATES[e.state]) {
state.value = appendState(state.value, STATES[e.state]);
}
touchPosition.value = { x: e.absoluteX, y: e.absoluteY };
})
.onEnd((e) => {
state.value = appendState(state.value, STATES[e.state]);
})
.onFinalize((e) => {
state.value = appendState(state.value, STATES[e.state]);
touchPosition.value = { x: null, y: null };
})
.simultaneousWithExternalGesture(scrollRef)
.withRef(panRef);
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<View style={{ flex: 1 }}>
{/** Logger */}
<View style={{ padding: 16, height: 180, justifyContent: 'flex-end' }}>
<ReText text={touchPositionX} />
<ReText text={touchPositionY} />
<Text>Gesture States (New -> Old):</Text>
<ReText text={stateString} />
</View>
{/** ScrollView with pan gesture */}
<GestureDetector gesture={panGesture}>
<Animated.View style={{ flex: 1 }}>
<CustomScrollComponent
disallowInterruption={false}
scrollEnabled={true}
ref={scrollRef}
style={{ flex: 1 }}
simultaneousHandlers={panRef}>
<Text>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua. At vero eos et accusam et
justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores
et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus
est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. gubergren, no sea takimata sanctus
est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet.
</Text>
</CustomScrollComponent>
</Animated.View>
</GestureDetector>
</View>
</GestureHandlerRootView>
);
}

XSLT value-of not showing new paragraphs

I have problem of getting text from xml in original state.
When I use <xsl:value-of select="desc" /> I get full text, but merged, without spaces between paragraphs.
I have data like this:
<desc><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat]]>
</desc>
And, as output I get this:
This is not good for me, because I want output text to be same as inside CDATA[], with blank lines between paragraphs.
I tried with using preserved spaces.
I'm using Saxon xslt processor
Using fo:block linefeed-treatment="preserve" as your container element might suffice, see https://www.w3.org/TR/xsl11/#linefeed-treatment.

How to break long strings in XAML source code?

Silly question, but a Google/SO search didn't bring me the desired result. I have a very long string like this:
<Label Text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
VerticalOptions="Start"
HorizontalOptions="StartAndExpand" />
How can I break up the Text attribute on multiple lines to have a better code formatting? Is there an option or not?
If I enter a new line and add some spaces (for indenting), the label also contains the spaces ...
It's funny I've not really thought about this one before but it's a great question! I always just kept word wrap on the editor so I never noticed...
That looks like xamarin? If so you might add that tag since wpf etc would be <Label Content="blah"/> format so it confused me at first.
However, in WPF, Silverlight, UWP, etc, you can just do this and skip the measuring of the ContentPresenter to display as a whole line and wrap accordingly when rendered;
<Label>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
erat, sed diam voluptua. At vero eos et accusam et justo duo
dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
sanctus est Lorem ipsum dolor sit amet.
</Label>
Unfortunately I don't use xamarin currently so if it turns out to be different just me know and I'll del this answer but hope it helps.
This problem has nothing to do with Xamarin. I use WPF and I had the same problem.
The problem does not only occur in a Label, it is in all Controls. Every Control has a Text property.
The cause is that you use the Text property to assign your text, using Text="..."
The solution, as Chris W suggested (maybe without realizing it), is to move the assignment of the Text property to the part between the opening tag and the closing tag; so to the part between <...> and </...>
So Instead of
<TextBox Height="auto" TextWrapping="Wrap"
Text="Lorem ipsum dolor sit amet, consetetur ... (etc.)"/>
Use:
<TextBox Height="auto" TextWrapping="Wrap">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore
... (etc.)
<TextBox>
Even the spaces / tabs in front of the text will be replaced by one space.
Note that if you use property assignment, you use string quotes: Text="...";
If you use the part between opening and closing tag, there are no string quotes.
That might be the reason that you can add line breaks in your source code.

Indenting plain text in a .text.haml file in a rails app

In my rails 3.1 app I am working on a text email backup and want it to show up in the email client as text separated into new lines like this:
Lorem ipsum dolor sit amet
Consectetur adipisicing elit
Sed do eiusmod tempor incididunt
Ut labore et d Lorem ipsum dolor sit amet Consectetur adipisicing elit Sed do eiusmod tempor incididunt Ut labore et dolore magna aliquaolore magna aliqua
In my .text.haml file I have tried to use this:
:plain
Lorem ipsum dolor sit amet
Consectetur adipisicing elit
Sed do eiusmod tempor incididunt
Ut labore et dolore magna aliqua
However, when I check it in gmail it appears condensed into one paragraph like this:
Lorem ipsum dolor sit amet Consectetur adipisicing elit Sed do eiusmod tempor incididunt Ut labore et dolore magna aliqua
What can I do to get this to work? When I copy and paste this code into a view file, and view source, it appears as text as I want it in the view source, but gets condensed into one paragraph in the browser. Does this perhaps indicate that gmail is taking the text and formatting it that way and I don't actually have a problem?
I don't have a setup to test this, but I believe you want either :escaped or :preserve (probably the latter).
If those don't work, see http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#filters for others (including info on how to create your own).

create pdf with long lines, fit to pagewidth without wordwrap

i'd like to create a large pdf (not typical page size) with long lines, max ~1000 characters / line, where the page size and font are such that no lines need to wrap.
the intention is not for the text in this document to be readable when the full page is viewed on any reasonably-sized monitor -- instead the reader can zoom to individual portions of interest within the document.
i attempted this with a small font in latex, but no success.
any help is greatly appreciated. thanks.
This works with pdflatex:
\documentclass{article}
\pdfpagewidth 200cm
\pdfpageheight 200cm
\textwidth 190cm
\def\lorem{Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.}
\begin{document}
\lorem \lorem \lorem \lorem
\end{document}